| | | 1 | | using Cysharp.Threading.Tasks.Internal; |
| | | 2 | | using System; |
| | | 3 | | using System.Threading; |
| | | 4 | | |
| | | 5 | | namespace Cysharp.Threading.Tasks.Linq |
| | | 6 | | { |
| | | 7 | | public static partial class UniTaskAsyncEnumerable |
| | | 8 | | { |
| | | 9 | | public static IUniTaskAsyncEnumerable<TResult> CombineLatest<T1, T2, TResult>(this IUniTaskAsyncEnumerable<T1> s |
| | | 10 | | { |
| | | 11 | | Error.ThrowArgumentNullException(source1, nameof(source1)); |
| | | 12 | | Error.ThrowArgumentNullException(source2, nameof(source2)); |
| | | 13 | | Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector)); |
| | | 14 | | |
| | | 15 | | return new CombineLatest<T1, T2, TResult>(source1, source2, resultSelector); |
| | | 16 | | } |
| | | 17 | | |
| | | 18 | | public static IUniTaskAsyncEnumerable<TResult> CombineLatest<T1, T2, T3, TResult>(this IUniTaskAsyncEnumerable<T |
| | | 19 | | { |
| | | 20 | | Error.ThrowArgumentNullException(source1, nameof(source1)); |
| | | 21 | | Error.ThrowArgumentNullException(source2, nameof(source2)); |
| | | 22 | | Error.ThrowArgumentNullException(source3, nameof(source3)); |
| | | 23 | | Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector)); |
| | | 24 | | |
| | | 25 | | return new CombineLatest<T1, T2, T3, TResult>(source1, source2, source3, resultSelector); |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | public static IUniTaskAsyncEnumerable<TResult> CombineLatest<T1, T2, T3, T4, TResult>(this IUniTaskAsyncEnumerab |
| | | 29 | | { |
| | | 30 | | Error.ThrowArgumentNullException(source1, nameof(source1)); |
| | | 31 | | Error.ThrowArgumentNullException(source2, nameof(source2)); |
| | | 32 | | Error.ThrowArgumentNullException(source3, nameof(source3)); |
| | | 33 | | Error.ThrowArgumentNullException(source4, nameof(source4)); |
| | | 34 | | Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector)); |
| | | 35 | | |
| | | 36 | | return new CombineLatest<T1, T2, T3, T4, TResult>(source1, source2, source3, source4, resultSelector); |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | public static IUniTaskAsyncEnumerable<TResult> CombineLatest<T1, T2, T3, T4, T5, TResult>(this IUniTaskAsyncEnum |
| | | 40 | | { |
| | | 41 | | Error.ThrowArgumentNullException(source1, nameof(source1)); |
| | | 42 | | Error.ThrowArgumentNullException(source2, nameof(source2)); |
| | | 43 | | Error.ThrowArgumentNullException(source3, nameof(source3)); |
| | | 44 | | Error.ThrowArgumentNullException(source4, nameof(source4)); |
| | | 45 | | Error.ThrowArgumentNullException(source5, nameof(source5)); |
| | | 46 | | Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector)); |
| | | 47 | | |
| | | 48 | | return new CombineLatest<T1, T2, T3, T4, T5, TResult>(source1, source2, source3, source4, source5, resultSel |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | public static IUniTaskAsyncEnumerable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, TResult>(this IUniTaskAsync |
| | | 52 | | { |
| | | 53 | | Error.ThrowArgumentNullException(source1, nameof(source1)); |
| | | 54 | | Error.ThrowArgumentNullException(source2, nameof(source2)); |
| | | 55 | | Error.ThrowArgumentNullException(source3, nameof(source3)); |
| | | 56 | | Error.ThrowArgumentNullException(source4, nameof(source4)); |
| | | 57 | | Error.ThrowArgumentNullException(source5, nameof(source5)); |
| | | 58 | | Error.ThrowArgumentNullException(source6, nameof(source6)); |
| | | 59 | | Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector)); |
| | | 60 | | |
| | | 61 | | return new CombineLatest<T1, T2, T3, T4, T5, T6, TResult>(source1, source2, source3, source4, source5, sourc |
| | | 62 | | } |
| | | 63 | | |
| | | 64 | | public static IUniTaskAsyncEnumerable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, TResult>(this IUniTaskA |
| | | 65 | | { |
| | | 66 | | Error.ThrowArgumentNullException(source1, nameof(source1)); |
| | | 67 | | Error.ThrowArgumentNullException(source2, nameof(source2)); |
| | | 68 | | Error.ThrowArgumentNullException(source3, nameof(source3)); |
| | | 69 | | Error.ThrowArgumentNullException(source4, nameof(source4)); |
| | | 70 | | Error.ThrowArgumentNullException(source5, nameof(source5)); |
| | | 71 | | Error.ThrowArgumentNullException(source6, nameof(source6)); |
| | | 72 | | Error.ThrowArgumentNullException(source7, nameof(source7)); |
| | | 73 | | Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector)); |
| | | 74 | | |
| | | 75 | | return new CombineLatest<T1, T2, T3, T4, T5, T6, T7, TResult>(source1, source2, source3, source4, source5, s |
| | | 76 | | } |
| | | 77 | | |
| | | 78 | | public static IUniTaskAsyncEnumerable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(this IUniT |
| | | 79 | | { |
| | | 80 | | Error.ThrowArgumentNullException(source1, nameof(source1)); |
| | | 81 | | Error.ThrowArgumentNullException(source2, nameof(source2)); |
| | | 82 | | Error.ThrowArgumentNullException(source3, nameof(source3)); |
| | | 83 | | Error.ThrowArgumentNullException(source4, nameof(source4)); |
| | | 84 | | Error.ThrowArgumentNullException(source5, nameof(source5)); |
| | | 85 | | Error.ThrowArgumentNullException(source6, nameof(source6)); |
| | | 86 | | Error.ThrowArgumentNullException(source7, nameof(source7)); |
| | | 87 | | Error.ThrowArgumentNullException(source8, nameof(source8)); |
| | | 88 | | Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector)); |
| | | 89 | | |
| | | 90 | | return new CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(source1, source2, source3, source4, source |
| | | 91 | | } |
| | | 92 | | |
| | | 93 | | public static IUniTaskAsyncEnumerable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(this I |
| | | 94 | | { |
| | | 95 | | Error.ThrowArgumentNullException(source1, nameof(source1)); |
| | | 96 | | Error.ThrowArgumentNullException(source2, nameof(source2)); |
| | | 97 | | Error.ThrowArgumentNullException(source3, nameof(source3)); |
| | | 98 | | Error.ThrowArgumentNullException(source4, nameof(source4)); |
| | | 99 | | Error.ThrowArgumentNullException(source5, nameof(source5)); |
| | | 100 | | Error.ThrowArgumentNullException(source6, nameof(source6)); |
| | | 101 | | Error.ThrowArgumentNullException(source7, nameof(source7)); |
| | | 102 | | Error.ThrowArgumentNullException(source8, nameof(source8)); |
| | | 103 | | Error.ThrowArgumentNullException(source9, nameof(source9)); |
| | | 104 | | Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector)); |
| | | 105 | | |
| | | 106 | | return new CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(source1, source2, source3, source4, so |
| | | 107 | | } |
| | | 108 | | |
| | | 109 | | public static IUniTaskAsyncEnumerable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(t |
| | | 110 | | { |
| | | 111 | | Error.ThrowArgumentNullException(source1, nameof(source1)); |
| | | 112 | | Error.ThrowArgumentNullException(source2, nameof(source2)); |
| | | 113 | | Error.ThrowArgumentNullException(source3, nameof(source3)); |
| | | 114 | | Error.ThrowArgumentNullException(source4, nameof(source4)); |
| | | 115 | | Error.ThrowArgumentNullException(source5, nameof(source5)); |
| | | 116 | | Error.ThrowArgumentNullException(source6, nameof(source6)); |
| | | 117 | | Error.ThrowArgumentNullException(source7, nameof(source7)); |
| | | 118 | | Error.ThrowArgumentNullException(source8, nameof(source8)); |
| | | 119 | | Error.ThrowArgumentNullException(source9, nameof(source9)); |
| | | 120 | | Error.ThrowArgumentNullException(source10, nameof(source10)); |
| | | 121 | | Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector)); |
| | | 122 | | |
| | | 123 | | return new CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(source1, source2, source3, source |
| | | 124 | | } |
| | | 125 | | |
| | | 126 | | public static IUniTaskAsyncEnumerable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResu |
| | | 127 | | { |
| | | 128 | | Error.ThrowArgumentNullException(source1, nameof(source1)); |
| | | 129 | | Error.ThrowArgumentNullException(source2, nameof(source2)); |
| | | 130 | | Error.ThrowArgumentNullException(source3, nameof(source3)); |
| | | 131 | | Error.ThrowArgumentNullException(source4, nameof(source4)); |
| | | 132 | | Error.ThrowArgumentNullException(source5, nameof(source5)); |
| | | 133 | | Error.ThrowArgumentNullException(source6, nameof(source6)); |
| | | 134 | | Error.ThrowArgumentNullException(source7, nameof(source7)); |
| | | 135 | | Error.ThrowArgumentNullException(source8, nameof(source8)); |
| | | 136 | | Error.ThrowArgumentNullException(source9, nameof(source9)); |
| | | 137 | | Error.ThrowArgumentNullException(source10, nameof(source10)); |
| | | 138 | | Error.ThrowArgumentNullException(source11, nameof(source11)); |
| | | 139 | | Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector)); |
| | | 140 | | |
| | | 141 | | return new CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>(source1, source2, source3, s |
| | | 142 | | } |
| | | 143 | | |
| | | 144 | | public static IUniTaskAsyncEnumerable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, |
| | | 145 | | { |
| | | 146 | | Error.ThrowArgumentNullException(source1, nameof(source1)); |
| | | 147 | | Error.ThrowArgumentNullException(source2, nameof(source2)); |
| | | 148 | | Error.ThrowArgumentNullException(source3, nameof(source3)); |
| | | 149 | | Error.ThrowArgumentNullException(source4, nameof(source4)); |
| | | 150 | | Error.ThrowArgumentNullException(source5, nameof(source5)); |
| | | 151 | | Error.ThrowArgumentNullException(source6, nameof(source6)); |
| | | 152 | | Error.ThrowArgumentNullException(source7, nameof(source7)); |
| | | 153 | | Error.ThrowArgumentNullException(source8, nameof(source8)); |
| | | 154 | | Error.ThrowArgumentNullException(source9, nameof(source9)); |
| | | 155 | | Error.ThrowArgumentNullException(source10, nameof(source10)); |
| | | 156 | | Error.ThrowArgumentNullException(source11, nameof(source11)); |
| | | 157 | | Error.ThrowArgumentNullException(source12, nameof(source12)); |
| | | 158 | | Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector)); |
| | | 159 | | |
| | | 160 | | return new CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult>(source1, source2, sourc |
| | | 161 | | } |
| | | 162 | | |
| | | 163 | | public static IUniTaskAsyncEnumerable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, |
| | | 164 | | { |
| | | 165 | | Error.ThrowArgumentNullException(source1, nameof(source1)); |
| | | 166 | | Error.ThrowArgumentNullException(source2, nameof(source2)); |
| | | 167 | | Error.ThrowArgumentNullException(source3, nameof(source3)); |
| | | 168 | | Error.ThrowArgumentNullException(source4, nameof(source4)); |
| | | 169 | | Error.ThrowArgumentNullException(source5, nameof(source5)); |
| | | 170 | | Error.ThrowArgumentNullException(source6, nameof(source6)); |
| | | 171 | | Error.ThrowArgumentNullException(source7, nameof(source7)); |
| | | 172 | | Error.ThrowArgumentNullException(source8, nameof(source8)); |
| | | 173 | | Error.ThrowArgumentNullException(source9, nameof(source9)); |
| | | 174 | | Error.ThrowArgumentNullException(source10, nameof(source10)); |
| | | 175 | | Error.ThrowArgumentNullException(source11, nameof(source11)); |
| | | 176 | | Error.ThrowArgumentNullException(source12, nameof(source12)); |
| | | 177 | | Error.ThrowArgumentNullException(source13, nameof(source13)); |
| | | 178 | | Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector)); |
| | | 179 | | |
| | | 180 | | return new CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult>(source1, source2, |
| | | 181 | | } |
| | | 182 | | |
| | | 183 | | public static IUniTaskAsyncEnumerable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, |
| | | 184 | | { |
| | | 185 | | Error.ThrowArgumentNullException(source1, nameof(source1)); |
| | | 186 | | Error.ThrowArgumentNullException(source2, nameof(source2)); |
| | | 187 | | Error.ThrowArgumentNullException(source3, nameof(source3)); |
| | | 188 | | Error.ThrowArgumentNullException(source4, nameof(source4)); |
| | | 189 | | Error.ThrowArgumentNullException(source5, nameof(source5)); |
| | | 190 | | Error.ThrowArgumentNullException(source6, nameof(source6)); |
| | | 191 | | Error.ThrowArgumentNullException(source7, nameof(source7)); |
| | | 192 | | Error.ThrowArgumentNullException(source8, nameof(source8)); |
| | | 193 | | Error.ThrowArgumentNullException(source9, nameof(source9)); |
| | | 194 | | Error.ThrowArgumentNullException(source10, nameof(source10)); |
| | | 195 | | Error.ThrowArgumentNullException(source11, nameof(source11)); |
| | | 196 | | Error.ThrowArgumentNullException(source12, nameof(source12)); |
| | | 197 | | Error.ThrowArgumentNullException(source13, nameof(source13)); |
| | | 198 | | Error.ThrowArgumentNullException(source14, nameof(source14)); |
| | | 199 | | Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector)); |
| | | 200 | | |
| | | 201 | | return new CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult>(source1, sour |
| | | 202 | | } |
| | | 203 | | |
| | | 204 | | public static IUniTaskAsyncEnumerable<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, |
| | | 205 | | { |
| | | 206 | | Error.ThrowArgumentNullException(source1, nameof(source1)); |
| | | 207 | | Error.ThrowArgumentNullException(source2, nameof(source2)); |
| | | 208 | | Error.ThrowArgumentNullException(source3, nameof(source3)); |
| | | 209 | | Error.ThrowArgumentNullException(source4, nameof(source4)); |
| | | 210 | | Error.ThrowArgumentNullException(source5, nameof(source5)); |
| | | 211 | | Error.ThrowArgumentNullException(source6, nameof(source6)); |
| | | 212 | | Error.ThrowArgumentNullException(source7, nameof(source7)); |
| | | 213 | | Error.ThrowArgumentNullException(source8, nameof(source8)); |
| | | 214 | | Error.ThrowArgumentNullException(source9, nameof(source9)); |
| | | 215 | | Error.ThrowArgumentNullException(source10, nameof(source10)); |
| | | 216 | | Error.ThrowArgumentNullException(source11, nameof(source11)); |
| | | 217 | | Error.ThrowArgumentNullException(source12, nameof(source12)); |
| | | 218 | | Error.ThrowArgumentNullException(source13, nameof(source13)); |
| | | 219 | | Error.ThrowArgumentNullException(source14, nameof(source14)); |
| | | 220 | | Error.ThrowArgumentNullException(source15, nameof(source15)); |
| | | 221 | | Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector)); |
| | | 222 | | |
| | | 223 | | return new CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult>(source1, |
| | | 224 | | } |
| | | 225 | | |
| | | 226 | | } |
| | | 227 | | |
| | | 228 | | internal class CombineLatest<T1, T2, TResult> : IUniTaskAsyncEnumerable<TResult> |
| | | 229 | | { |
| | | 230 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 231 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 232 | | |
| | | 233 | | readonly Func<T1, T2, TResult> resultSelector; |
| | | 234 | | |
| | | 235 | | public CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, Func<T1, T2, TRes |
| | | 236 | | { |
| | | 237 | | this.source1 = source1; |
| | | 238 | | this.source2 = source2; |
| | | 239 | | |
| | | 240 | | this.resultSelector = resultSelector; |
| | | 241 | | } |
| | | 242 | | |
| | | 243 | | public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default) |
| | | 244 | | { |
| | | 245 | | return new _CombineLatest(source1, source2, resultSelector, cancellationToken); |
| | | 246 | | } |
| | | 247 | | |
| | | 248 | | class _CombineLatest : MoveNextSource, IUniTaskAsyncEnumerator<TResult> |
| | | 249 | | { |
| | | 250 | | static readonly Action<object> Completed1Delegate = Completed1; |
| | | 251 | | static readonly Action<object> Completed2Delegate = Completed2; |
| | | 252 | | const int CompleteCount = 2; |
| | | 253 | | |
| | | 254 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 255 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 256 | | |
| | | 257 | | readonly Func<T1, T2, TResult> resultSelector; |
| | | 258 | | CancellationToken cancellationToken; |
| | | 259 | | |
| | | 260 | | IUniTaskAsyncEnumerator<T1> enumerator1; |
| | | 261 | | UniTask<bool>.Awaiter awaiter1; |
| | | 262 | | bool hasCurrent1; |
| | | 263 | | bool running1; |
| | | 264 | | T1 current1; |
| | | 265 | | |
| | | 266 | | IUniTaskAsyncEnumerator<T2> enumerator2; |
| | | 267 | | UniTask<bool>.Awaiter awaiter2; |
| | | 268 | | bool hasCurrent2; |
| | | 269 | | bool running2; |
| | | 270 | | T2 current2; |
| | | 271 | | |
| | | 272 | | int completedCount; |
| | | 273 | | bool syncRunning; |
| | | 274 | | TResult result; |
| | | 275 | | |
| | | 276 | | public _CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, Func<T1, T2, |
| | | 277 | | { |
| | | 278 | | this.source1 = source1; |
| | | 279 | | this.source2 = source2; |
| | | 280 | | |
| | | 281 | | this.resultSelector = resultSelector; |
| | | 282 | | this.cancellationToken = cancellationToken; |
| | | 283 | | TaskTracker.TrackActiveTask(this, 3); |
| | | 284 | | } |
| | | 285 | | |
| | | 286 | | public TResult Current => result; |
| | | 287 | | |
| | | 288 | | public UniTask<bool> MoveNextAsync() |
| | | 289 | | { |
| | | 290 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 291 | | if (completedCount == CompleteCount) return CompletedTasks.False; |
| | | 292 | | |
| | | 293 | | if (enumerator1 == null) |
| | | 294 | | { |
| | | 295 | | enumerator1 = source1.GetAsyncEnumerator(cancellationToken); |
| | | 296 | | enumerator2 = source2.GetAsyncEnumerator(cancellationToken); |
| | | 297 | | } |
| | | 298 | | |
| | | 299 | | completionSource.Reset(); |
| | | 300 | | |
| | | 301 | | AGAIN: |
| | | 302 | | syncRunning = true; |
| | | 303 | | if (!running1) |
| | | 304 | | { |
| | | 305 | | running1 = true; |
| | | 306 | | awaiter1 = enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 307 | | if (awaiter1.IsCompleted) |
| | | 308 | | { |
| | | 309 | | Completed1(this); |
| | | 310 | | } |
| | | 311 | | else |
| | | 312 | | { |
| | | 313 | | awaiter1.SourceOnCompleted(Completed1Delegate, this); |
| | | 314 | | } |
| | | 315 | | } |
| | | 316 | | if (!running2) |
| | | 317 | | { |
| | | 318 | | running2 = true; |
| | | 319 | | awaiter2 = enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 320 | | if (awaiter2.IsCompleted) |
| | | 321 | | { |
| | | 322 | | Completed2(this); |
| | | 323 | | } |
| | | 324 | | else |
| | | 325 | | { |
| | | 326 | | awaiter2.SourceOnCompleted(Completed2Delegate, this); |
| | | 327 | | } |
| | | 328 | | } |
| | | 329 | | |
| | | 330 | | if (!running1 || !running2) |
| | | 331 | | { |
| | | 332 | | goto AGAIN; |
| | | 333 | | } |
| | | 334 | | syncRunning = false; |
| | | 335 | | |
| | | 336 | | return new UniTask<bool>(this, completionSource.Version); |
| | | 337 | | } |
| | | 338 | | |
| | | 339 | | static void Completed1(object state) |
| | | 340 | | { |
| | | 341 | | var self = (_CombineLatest)state; |
| | | 342 | | self.running1 = false; |
| | | 343 | | |
| | | 344 | | try |
| | | 345 | | { |
| | | 346 | | if (self.awaiter1.GetResult()) |
| | | 347 | | { |
| | | 348 | | self.hasCurrent1 = true; |
| | | 349 | | self.current1 = self.enumerator1.Current; |
| | | 350 | | goto SUCCESS; |
| | | 351 | | } |
| | | 352 | | else |
| | | 353 | | { |
| | | 354 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 355 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 356 | | { |
| | | 357 | | goto COMPLETE; |
| | | 358 | | } |
| | | 359 | | return; |
| | | 360 | | } |
| | | 361 | | } |
| | | 362 | | catch (Exception ex) |
| | | 363 | | { |
| | | 364 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 365 | | self.completedCount = CompleteCount; |
| | | 366 | | self.completionSource.TrySetException(ex); |
| | | 367 | | return; |
| | | 368 | | } |
| | | 369 | | |
| | | 370 | | SUCCESS: |
| | | 371 | | if (!self.TrySetResult()) |
| | | 372 | | { |
| | | 373 | | if (self.syncRunning) return; |
| | | 374 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 375 | | try |
| | | 376 | | { |
| | | 377 | | self.awaiter1 = self.enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 378 | | } |
| | | 379 | | catch (Exception ex) |
| | | 380 | | { |
| | | 381 | | self.completedCount = CompleteCount; |
| | | 382 | | self.completionSource.TrySetException(ex); |
| | | 383 | | return; |
| | | 384 | | } |
| | | 385 | | |
| | | 386 | | self.awaiter1.SourceOnCompleted(Completed1Delegate, self); |
| | | 387 | | } |
| | | 388 | | return; |
| | | 389 | | COMPLETE: |
| | | 390 | | self.completionSource.TrySetResult(false); |
| | | 391 | | return; |
| | | 392 | | } |
| | | 393 | | |
| | | 394 | | static void Completed2(object state) |
| | | 395 | | { |
| | | 396 | | var self = (_CombineLatest)state; |
| | | 397 | | self.running2 = false; |
| | | 398 | | |
| | | 399 | | try |
| | | 400 | | { |
| | | 401 | | if (self.awaiter2.GetResult()) |
| | | 402 | | { |
| | | 403 | | self.hasCurrent2 = true; |
| | | 404 | | self.current2 = self.enumerator2.Current; |
| | | 405 | | goto SUCCESS; |
| | | 406 | | } |
| | | 407 | | else |
| | | 408 | | { |
| | | 409 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 410 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 411 | | { |
| | | 412 | | goto COMPLETE; |
| | | 413 | | } |
| | | 414 | | return; |
| | | 415 | | } |
| | | 416 | | } |
| | | 417 | | catch (Exception ex) |
| | | 418 | | { |
| | | 419 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 420 | | self.completedCount = CompleteCount; |
| | | 421 | | self.completionSource.TrySetException(ex); |
| | | 422 | | return; |
| | | 423 | | } |
| | | 424 | | |
| | | 425 | | SUCCESS: |
| | | 426 | | if (!self.TrySetResult()) |
| | | 427 | | { |
| | | 428 | | if (self.syncRunning) return; |
| | | 429 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 430 | | try |
| | | 431 | | { |
| | | 432 | | self.awaiter2 = self.enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 433 | | } |
| | | 434 | | catch (Exception ex) |
| | | 435 | | { |
| | | 436 | | self.completedCount = CompleteCount; |
| | | 437 | | self.completionSource.TrySetException(ex); |
| | | 438 | | return; |
| | | 439 | | } |
| | | 440 | | |
| | | 441 | | self.awaiter2.SourceOnCompleted(Completed2Delegate, self); |
| | | 442 | | } |
| | | 443 | | return; |
| | | 444 | | COMPLETE: |
| | | 445 | | self.completionSource.TrySetResult(false); |
| | | 446 | | return; |
| | | 447 | | } |
| | | 448 | | |
| | | 449 | | bool TrySetResult() |
| | | 450 | | { |
| | | 451 | | if (hasCurrent1 && hasCurrent2) |
| | | 452 | | { |
| | | 453 | | result = resultSelector(current1, current2); |
| | | 454 | | completionSource.TrySetResult(true); |
| | | 455 | | return true; |
| | | 456 | | } |
| | | 457 | | else |
| | | 458 | | { |
| | | 459 | | return false; |
| | | 460 | | } |
| | | 461 | | } |
| | | 462 | | |
| | | 463 | | public async UniTask DisposeAsync() |
| | | 464 | | { |
| | | 465 | | TaskTracker.RemoveTracking(this); |
| | | 466 | | if (enumerator1 != null) |
| | | 467 | | { |
| | | 468 | | await enumerator1.DisposeAsync(); |
| | | 469 | | } |
| | | 470 | | if (enumerator2 != null) |
| | | 471 | | { |
| | | 472 | | await enumerator2.DisposeAsync(); |
| | | 473 | | } |
| | | 474 | | } |
| | | 475 | | } |
| | | 476 | | } |
| | | 477 | | |
| | | 478 | | internal class CombineLatest<T1, T2, T3, TResult> : IUniTaskAsyncEnumerable<TResult> |
| | | 479 | | { |
| | | 480 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 481 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 482 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 483 | | |
| | | 484 | | readonly Func<T1, T2, T3, TResult> resultSelector; |
| | | 485 | | |
| | | 486 | | public CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyncEnum |
| | | 487 | | { |
| | | 488 | | this.source1 = source1; |
| | | 489 | | this.source2 = source2; |
| | | 490 | | this.source3 = source3; |
| | | 491 | | |
| | | 492 | | this.resultSelector = resultSelector; |
| | | 493 | | } |
| | | 494 | | |
| | | 495 | | public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default) |
| | | 496 | | { |
| | | 497 | | return new _CombineLatest(source1, source2, source3, resultSelector, cancellationToken); |
| | | 498 | | } |
| | | 499 | | |
| | | 500 | | class _CombineLatest : MoveNextSource, IUniTaskAsyncEnumerator<TResult> |
| | | 501 | | { |
| | | 502 | | static readonly Action<object> Completed1Delegate = Completed1; |
| | | 503 | | static readonly Action<object> Completed2Delegate = Completed2; |
| | | 504 | | static readonly Action<object> Completed3Delegate = Completed3; |
| | | 505 | | const int CompleteCount = 3; |
| | | 506 | | |
| | | 507 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 508 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 509 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 510 | | |
| | | 511 | | readonly Func<T1, T2, T3, TResult> resultSelector; |
| | | 512 | | CancellationToken cancellationToken; |
| | | 513 | | |
| | | 514 | | IUniTaskAsyncEnumerator<T1> enumerator1; |
| | | 515 | | UniTask<bool>.Awaiter awaiter1; |
| | | 516 | | bool hasCurrent1; |
| | | 517 | | bool running1; |
| | | 518 | | T1 current1; |
| | | 519 | | |
| | | 520 | | IUniTaskAsyncEnumerator<T2> enumerator2; |
| | | 521 | | UniTask<bool>.Awaiter awaiter2; |
| | | 522 | | bool hasCurrent2; |
| | | 523 | | bool running2; |
| | | 524 | | T2 current2; |
| | | 525 | | |
| | | 526 | | IUniTaskAsyncEnumerator<T3> enumerator3; |
| | | 527 | | UniTask<bool>.Awaiter awaiter3; |
| | | 528 | | bool hasCurrent3; |
| | | 529 | | bool running3; |
| | | 530 | | T3 current3; |
| | | 531 | | |
| | | 532 | | int completedCount; |
| | | 533 | | bool syncRunning; |
| | | 534 | | TResult result; |
| | | 535 | | |
| | | 536 | | public _CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyn |
| | | 537 | | { |
| | | 538 | | this.source1 = source1; |
| | | 539 | | this.source2 = source2; |
| | | 540 | | this.source3 = source3; |
| | | 541 | | |
| | | 542 | | this.resultSelector = resultSelector; |
| | | 543 | | this.cancellationToken = cancellationToken; |
| | | 544 | | TaskTracker.TrackActiveTask(this, 3); |
| | | 545 | | } |
| | | 546 | | |
| | | 547 | | public TResult Current => result; |
| | | 548 | | |
| | | 549 | | public UniTask<bool> MoveNextAsync() |
| | | 550 | | { |
| | | 551 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 552 | | if (completedCount == CompleteCount) return CompletedTasks.False; |
| | | 553 | | |
| | | 554 | | if (enumerator1 == null) |
| | | 555 | | { |
| | | 556 | | enumerator1 = source1.GetAsyncEnumerator(cancellationToken); |
| | | 557 | | enumerator2 = source2.GetAsyncEnumerator(cancellationToken); |
| | | 558 | | enumerator3 = source3.GetAsyncEnumerator(cancellationToken); |
| | | 559 | | } |
| | | 560 | | |
| | | 561 | | completionSource.Reset(); |
| | | 562 | | |
| | | 563 | | AGAIN: |
| | | 564 | | syncRunning = true; |
| | | 565 | | if (!running1) |
| | | 566 | | { |
| | | 567 | | running1 = true; |
| | | 568 | | awaiter1 = enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 569 | | if (awaiter1.IsCompleted) |
| | | 570 | | { |
| | | 571 | | Completed1(this); |
| | | 572 | | } |
| | | 573 | | else |
| | | 574 | | { |
| | | 575 | | awaiter1.SourceOnCompleted(Completed1Delegate, this); |
| | | 576 | | } |
| | | 577 | | } |
| | | 578 | | if (!running2) |
| | | 579 | | { |
| | | 580 | | running2 = true; |
| | | 581 | | awaiter2 = enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 582 | | if (awaiter2.IsCompleted) |
| | | 583 | | { |
| | | 584 | | Completed2(this); |
| | | 585 | | } |
| | | 586 | | else |
| | | 587 | | { |
| | | 588 | | awaiter2.SourceOnCompleted(Completed2Delegate, this); |
| | | 589 | | } |
| | | 590 | | } |
| | | 591 | | if (!running3) |
| | | 592 | | { |
| | | 593 | | running3 = true; |
| | | 594 | | awaiter3 = enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 595 | | if (awaiter3.IsCompleted) |
| | | 596 | | { |
| | | 597 | | Completed3(this); |
| | | 598 | | } |
| | | 599 | | else |
| | | 600 | | { |
| | | 601 | | awaiter3.SourceOnCompleted(Completed3Delegate, this); |
| | | 602 | | } |
| | | 603 | | } |
| | | 604 | | |
| | | 605 | | if (!running1 || !running2 || !running3) |
| | | 606 | | { |
| | | 607 | | goto AGAIN; |
| | | 608 | | } |
| | | 609 | | syncRunning = false; |
| | | 610 | | |
| | | 611 | | return new UniTask<bool>(this, completionSource.Version); |
| | | 612 | | } |
| | | 613 | | |
| | | 614 | | static void Completed1(object state) |
| | | 615 | | { |
| | | 616 | | var self = (_CombineLatest)state; |
| | | 617 | | self.running1 = false; |
| | | 618 | | |
| | | 619 | | try |
| | | 620 | | { |
| | | 621 | | if (self.awaiter1.GetResult()) |
| | | 622 | | { |
| | | 623 | | self.hasCurrent1 = true; |
| | | 624 | | self.current1 = self.enumerator1.Current; |
| | | 625 | | goto SUCCESS; |
| | | 626 | | } |
| | | 627 | | else |
| | | 628 | | { |
| | | 629 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 630 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 631 | | { |
| | | 632 | | goto COMPLETE; |
| | | 633 | | } |
| | | 634 | | return; |
| | | 635 | | } |
| | | 636 | | } |
| | | 637 | | catch (Exception ex) |
| | | 638 | | { |
| | | 639 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 640 | | self.completedCount = CompleteCount; |
| | | 641 | | self.completionSource.TrySetException(ex); |
| | | 642 | | return; |
| | | 643 | | } |
| | | 644 | | |
| | | 645 | | SUCCESS: |
| | | 646 | | if (!self.TrySetResult()) |
| | | 647 | | { |
| | | 648 | | if (self.syncRunning) return; |
| | | 649 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 650 | | try |
| | | 651 | | { |
| | | 652 | | self.awaiter1 = self.enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 653 | | } |
| | | 654 | | catch (Exception ex) |
| | | 655 | | { |
| | | 656 | | self.completedCount = CompleteCount; |
| | | 657 | | self.completionSource.TrySetException(ex); |
| | | 658 | | return; |
| | | 659 | | } |
| | | 660 | | |
| | | 661 | | self.awaiter1.SourceOnCompleted(Completed1Delegate, self); |
| | | 662 | | } |
| | | 663 | | return; |
| | | 664 | | COMPLETE: |
| | | 665 | | self.completionSource.TrySetResult(false); |
| | | 666 | | return; |
| | | 667 | | } |
| | | 668 | | |
| | | 669 | | static void Completed2(object state) |
| | | 670 | | { |
| | | 671 | | var self = (_CombineLatest)state; |
| | | 672 | | self.running2 = false; |
| | | 673 | | |
| | | 674 | | try |
| | | 675 | | { |
| | | 676 | | if (self.awaiter2.GetResult()) |
| | | 677 | | { |
| | | 678 | | self.hasCurrent2 = true; |
| | | 679 | | self.current2 = self.enumerator2.Current; |
| | | 680 | | goto SUCCESS; |
| | | 681 | | } |
| | | 682 | | else |
| | | 683 | | { |
| | | 684 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 685 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 686 | | { |
| | | 687 | | goto COMPLETE; |
| | | 688 | | } |
| | | 689 | | return; |
| | | 690 | | } |
| | | 691 | | } |
| | | 692 | | catch (Exception ex) |
| | | 693 | | { |
| | | 694 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 695 | | self.completedCount = CompleteCount; |
| | | 696 | | self.completionSource.TrySetException(ex); |
| | | 697 | | return; |
| | | 698 | | } |
| | | 699 | | |
| | | 700 | | SUCCESS: |
| | | 701 | | if (!self.TrySetResult()) |
| | | 702 | | { |
| | | 703 | | if (self.syncRunning) return; |
| | | 704 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 705 | | try |
| | | 706 | | { |
| | | 707 | | self.awaiter2 = self.enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 708 | | } |
| | | 709 | | catch (Exception ex) |
| | | 710 | | { |
| | | 711 | | self.completedCount = CompleteCount; |
| | | 712 | | self.completionSource.TrySetException(ex); |
| | | 713 | | return; |
| | | 714 | | } |
| | | 715 | | |
| | | 716 | | self.awaiter2.SourceOnCompleted(Completed2Delegate, self); |
| | | 717 | | } |
| | | 718 | | return; |
| | | 719 | | COMPLETE: |
| | | 720 | | self.completionSource.TrySetResult(false); |
| | | 721 | | return; |
| | | 722 | | } |
| | | 723 | | |
| | | 724 | | static void Completed3(object state) |
| | | 725 | | { |
| | | 726 | | var self = (_CombineLatest)state; |
| | | 727 | | self.running3 = false; |
| | | 728 | | |
| | | 729 | | try |
| | | 730 | | { |
| | | 731 | | if (self.awaiter3.GetResult()) |
| | | 732 | | { |
| | | 733 | | self.hasCurrent3 = true; |
| | | 734 | | self.current3 = self.enumerator3.Current; |
| | | 735 | | goto SUCCESS; |
| | | 736 | | } |
| | | 737 | | else |
| | | 738 | | { |
| | | 739 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 740 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 741 | | { |
| | | 742 | | goto COMPLETE; |
| | | 743 | | } |
| | | 744 | | return; |
| | | 745 | | } |
| | | 746 | | } |
| | | 747 | | catch (Exception ex) |
| | | 748 | | { |
| | | 749 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 750 | | self.completedCount = CompleteCount; |
| | | 751 | | self.completionSource.TrySetException(ex); |
| | | 752 | | return; |
| | | 753 | | } |
| | | 754 | | |
| | | 755 | | SUCCESS: |
| | | 756 | | if (!self.TrySetResult()) |
| | | 757 | | { |
| | | 758 | | if (self.syncRunning) return; |
| | | 759 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 760 | | try |
| | | 761 | | { |
| | | 762 | | self.awaiter3 = self.enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 763 | | } |
| | | 764 | | catch (Exception ex) |
| | | 765 | | { |
| | | 766 | | self.completedCount = CompleteCount; |
| | | 767 | | self.completionSource.TrySetException(ex); |
| | | 768 | | return; |
| | | 769 | | } |
| | | 770 | | |
| | | 771 | | self.awaiter3.SourceOnCompleted(Completed3Delegate, self); |
| | | 772 | | } |
| | | 773 | | return; |
| | | 774 | | COMPLETE: |
| | | 775 | | self.completionSource.TrySetResult(false); |
| | | 776 | | return; |
| | | 777 | | } |
| | | 778 | | |
| | | 779 | | bool TrySetResult() |
| | | 780 | | { |
| | | 781 | | if (hasCurrent1 && hasCurrent2 && hasCurrent3) |
| | | 782 | | { |
| | | 783 | | result = resultSelector(current1, current2, current3); |
| | | 784 | | completionSource.TrySetResult(true); |
| | | 785 | | return true; |
| | | 786 | | } |
| | | 787 | | else |
| | | 788 | | { |
| | | 789 | | return false; |
| | | 790 | | } |
| | | 791 | | } |
| | | 792 | | |
| | | 793 | | public async UniTask DisposeAsync() |
| | | 794 | | { |
| | | 795 | | TaskTracker.RemoveTracking(this); |
| | | 796 | | if (enumerator1 != null) |
| | | 797 | | { |
| | | 798 | | await enumerator1.DisposeAsync(); |
| | | 799 | | } |
| | | 800 | | if (enumerator2 != null) |
| | | 801 | | { |
| | | 802 | | await enumerator2.DisposeAsync(); |
| | | 803 | | } |
| | | 804 | | if (enumerator3 != null) |
| | | 805 | | { |
| | | 806 | | await enumerator3.DisposeAsync(); |
| | | 807 | | } |
| | | 808 | | } |
| | | 809 | | } |
| | | 810 | | } |
| | | 811 | | |
| | | 812 | | internal class CombineLatest<T1, T2, T3, T4, TResult> : IUniTaskAsyncEnumerable<TResult> |
| | | 813 | | { |
| | | 814 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 815 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 816 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 817 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 818 | | |
| | | 819 | | readonly Func<T1, T2, T3, T4, TResult> resultSelector; |
| | | 820 | | |
| | | 821 | | public CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyncEnum |
| | | 822 | | { |
| | | 823 | | this.source1 = source1; |
| | | 824 | | this.source2 = source2; |
| | | 825 | | this.source3 = source3; |
| | | 826 | | this.source4 = source4; |
| | | 827 | | |
| | | 828 | | this.resultSelector = resultSelector; |
| | | 829 | | } |
| | | 830 | | |
| | | 831 | | public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default) |
| | | 832 | | { |
| | | 833 | | return new _CombineLatest(source1, source2, source3, source4, resultSelector, cancellationToken); |
| | | 834 | | } |
| | | 835 | | |
| | | 836 | | class _CombineLatest : MoveNextSource, IUniTaskAsyncEnumerator<TResult> |
| | | 837 | | { |
| | | 838 | | static readonly Action<object> Completed1Delegate = Completed1; |
| | | 839 | | static readonly Action<object> Completed2Delegate = Completed2; |
| | | 840 | | static readonly Action<object> Completed3Delegate = Completed3; |
| | | 841 | | static readonly Action<object> Completed4Delegate = Completed4; |
| | | 842 | | const int CompleteCount = 4; |
| | | 843 | | |
| | | 844 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 845 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 846 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 847 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 848 | | |
| | | 849 | | readonly Func<T1, T2, T3, T4, TResult> resultSelector; |
| | | 850 | | CancellationToken cancellationToken; |
| | | 851 | | |
| | | 852 | | IUniTaskAsyncEnumerator<T1> enumerator1; |
| | | 853 | | UniTask<bool>.Awaiter awaiter1; |
| | | 854 | | bool hasCurrent1; |
| | | 855 | | bool running1; |
| | | 856 | | T1 current1; |
| | | 857 | | |
| | | 858 | | IUniTaskAsyncEnumerator<T2> enumerator2; |
| | | 859 | | UniTask<bool>.Awaiter awaiter2; |
| | | 860 | | bool hasCurrent2; |
| | | 861 | | bool running2; |
| | | 862 | | T2 current2; |
| | | 863 | | |
| | | 864 | | IUniTaskAsyncEnumerator<T3> enumerator3; |
| | | 865 | | UniTask<bool>.Awaiter awaiter3; |
| | | 866 | | bool hasCurrent3; |
| | | 867 | | bool running3; |
| | | 868 | | T3 current3; |
| | | 869 | | |
| | | 870 | | IUniTaskAsyncEnumerator<T4> enumerator4; |
| | | 871 | | UniTask<bool>.Awaiter awaiter4; |
| | | 872 | | bool hasCurrent4; |
| | | 873 | | bool running4; |
| | | 874 | | T4 current4; |
| | | 875 | | |
| | | 876 | | int completedCount; |
| | | 877 | | bool syncRunning; |
| | | 878 | | TResult result; |
| | | 879 | | |
| | | 880 | | public _CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyn |
| | | 881 | | { |
| | | 882 | | this.source1 = source1; |
| | | 883 | | this.source2 = source2; |
| | | 884 | | this.source3 = source3; |
| | | 885 | | this.source4 = source4; |
| | | 886 | | |
| | | 887 | | this.resultSelector = resultSelector; |
| | | 888 | | this.cancellationToken = cancellationToken; |
| | | 889 | | TaskTracker.TrackActiveTask(this, 3); |
| | | 890 | | } |
| | | 891 | | |
| | | 892 | | public TResult Current => result; |
| | | 893 | | |
| | | 894 | | public UniTask<bool> MoveNextAsync() |
| | | 895 | | { |
| | | 896 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 897 | | if (completedCount == CompleteCount) return CompletedTasks.False; |
| | | 898 | | |
| | | 899 | | if (enumerator1 == null) |
| | | 900 | | { |
| | | 901 | | enumerator1 = source1.GetAsyncEnumerator(cancellationToken); |
| | | 902 | | enumerator2 = source2.GetAsyncEnumerator(cancellationToken); |
| | | 903 | | enumerator3 = source3.GetAsyncEnumerator(cancellationToken); |
| | | 904 | | enumerator4 = source4.GetAsyncEnumerator(cancellationToken); |
| | | 905 | | } |
| | | 906 | | |
| | | 907 | | completionSource.Reset(); |
| | | 908 | | |
| | | 909 | | AGAIN: |
| | | 910 | | syncRunning = true; |
| | | 911 | | if (!running1) |
| | | 912 | | { |
| | | 913 | | running1 = true; |
| | | 914 | | awaiter1 = enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 915 | | if (awaiter1.IsCompleted) |
| | | 916 | | { |
| | | 917 | | Completed1(this); |
| | | 918 | | } |
| | | 919 | | else |
| | | 920 | | { |
| | | 921 | | awaiter1.SourceOnCompleted(Completed1Delegate, this); |
| | | 922 | | } |
| | | 923 | | } |
| | | 924 | | if (!running2) |
| | | 925 | | { |
| | | 926 | | running2 = true; |
| | | 927 | | awaiter2 = enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 928 | | if (awaiter2.IsCompleted) |
| | | 929 | | { |
| | | 930 | | Completed2(this); |
| | | 931 | | } |
| | | 932 | | else |
| | | 933 | | { |
| | | 934 | | awaiter2.SourceOnCompleted(Completed2Delegate, this); |
| | | 935 | | } |
| | | 936 | | } |
| | | 937 | | if (!running3) |
| | | 938 | | { |
| | | 939 | | running3 = true; |
| | | 940 | | awaiter3 = enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 941 | | if (awaiter3.IsCompleted) |
| | | 942 | | { |
| | | 943 | | Completed3(this); |
| | | 944 | | } |
| | | 945 | | else |
| | | 946 | | { |
| | | 947 | | awaiter3.SourceOnCompleted(Completed3Delegate, this); |
| | | 948 | | } |
| | | 949 | | } |
| | | 950 | | if (!running4) |
| | | 951 | | { |
| | | 952 | | running4 = true; |
| | | 953 | | awaiter4 = enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 954 | | if (awaiter4.IsCompleted) |
| | | 955 | | { |
| | | 956 | | Completed4(this); |
| | | 957 | | } |
| | | 958 | | else |
| | | 959 | | { |
| | | 960 | | awaiter4.SourceOnCompleted(Completed4Delegate, this); |
| | | 961 | | } |
| | | 962 | | } |
| | | 963 | | |
| | | 964 | | if (!running1 || !running2 || !running3 || !running4) |
| | | 965 | | { |
| | | 966 | | goto AGAIN; |
| | | 967 | | } |
| | | 968 | | syncRunning = false; |
| | | 969 | | |
| | | 970 | | return new UniTask<bool>(this, completionSource.Version); |
| | | 971 | | } |
| | | 972 | | |
| | | 973 | | static void Completed1(object state) |
| | | 974 | | { |
| | | 975 | | var self = (_CombineLatest)state; |
| | | 976 | | self.running1 = false; |
| | | 977 | | |
| | | 978 | | try |
| | | 979 | | { |
| | | 980 | | if (self.awaiter1.GetResult()) |
| | | 981 | | { |
| | | 982 | | self.hasCurrent1 = true; |
| | | 983 | | self.current1 = self.enumerator1.Current; |
| | | 984 | | goto SUCCESS; |
| | | 985 | | } |
| | | 986 | | else |
| | | 987 | | { |
| | | 988 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 989 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 990 | | { |
| | | 991 | | goto COMPLETE; |
| | | 992 | | } |
| | | 993 | | return; |
| | | 994 | | } |
| | | 995 | | } |
| | | 996 | | catch (Exception ex) |
| | | 997 | | { |
| | | 998 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 999 | | self.completedCount = CompleteCount; |
| | | 1000 | | self.completionSource.TrySetException(ex); |
| | | 1001 | | return; |
| | | 1002 | | } |
| | | 1003 | | |
| | | 1004 | | SUCCESS: |
| | | 1005 | | if (!self.TrySetResult()) |
| | | 1006 | | { |
| | | 1007 | | if (self.syncRunning) return; |
| | | 1008 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 1009 | | try |
| | | 1010 | | { |
| | | 1011 | | self.awaiter1 = self.enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 1012 | | } |
| | | 1013 | | catch (Exception ex) |
| | | 1014 | | { |
| | | 1015 | | self.completedCount = CompleteCount; |
| | | 1016 | | self.completionSource.TrySetException(ex); |
| | | 1017 | | return; |
| | | 1018 | | } |
| | | 1019 | | |
| | | 1020 | | self.awaiter1.SourceOnCompleted(Completed1Delegate, self); |
| | | 1021 | | } |
| | | 1022 | | return; |
| | | 1023 | | COMPLETE: |
| | | 1024 | | self.completionSource.TrySetResult(false); |
| | | 1025 | | return; |
| | | 1026 | | } |
| | | 1027 | | |
| | | 1028 | | static void Completed2(object state) |
| | | 1029 | | { |
| | | 1030 | | var self = (_CombineLatest)state; |
| | | 1031 | | self.running2 = false; |
| | | 1032 | | |
| | | 1033 | | try |
| | | 1034 | | { |
| | | 1035 | | if (self.awaiter2.GetResult()) |
| | | 1036 | | { |
| | | 1037 | | self.hasCurrent2 = true; |
| | | 1038 | | self.current2 = self.enumerator2.Current; |
| | | 1039 | | goto SUCCESS; |
| | | 1040 | | } |
| | | 1041 | | else |
| | | 1042 | | { |
| | | 1043 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 1044 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 1045 | | { |
| | | 1046 | | goto COMPLETE; |
| | | 1047 | | } |
| | | 1048 | | return; |
| | | 1049 | | } |
| | | 1050 | | } |
| | | 1051 | | catch (Exception ex) |
| | | 1052 | | { |
| | | 1053 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 1054 | | self.completedCount = CompleteCount; |
| | | 1055 | | self.completionSource.TrySetException(ex); |
| | | 1056 | | return; |
| | | 1057 | | } |
| | | 1058 | | |
| | | 1059 | | SUCCESS: |
| | | 1060 | | if (!self.TrySetResult()) |
| | | 1061 | | { |
| | | 1062 | | if (self.syncRunning) return; |
| | | 1063 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 1064 | | try |
| | | 1065 | | { |
| | | 1066 | | self.awaiter2 = self.enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 1067 | | } |
| | | 1068 | | catch (Exception ex) |
| | | 1069 | | { |
| | | 1070 | | self.completedCount = CompleteCount; |
| | | 1071 | | self.completionSource.TrySetException(ex); |
| | | 1072 | | return; |
| | | 1073 | | } |
| | | 1074 | | |
| | | 1075 | | self.awaiter2.SourceOnCompleted(Completed2Delegate, self); |
| | | 1076 | | } |
| | | 1077 | | return; |
| | | 1078 | | COMPLETE: |
| | | 1079 | | self.completionSource.TrySetResult(false); |
| | | 1080 | | return; |
| | | 1081 | | } |
| | | 1082 | | |
| | | 1083 | | static void Completed3(object state) |
| | | 1084 | | { |
| | | 1085 | | var self = (_CombineLatest)state; |
| | | 1086 | | self.running3 = false; |
| | | 1087 | | |
| | | 1088 | | try |
| | | 1089 | | { |
| | | 1090 | | if (self.awaiter3.GetResult()) |
| | | 1091 | | { |
| | | 1092 | | self.hasCurrent3 = true; |
| | | 1093 | | self.current3 = self.enumerator3.Current; |
| | | 1094 | | goto SUCCESS; |
| | | 1095 | | } |
| | | 1096 | | else |
| | | 1097 | | { |
| | | 1098 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 1099 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 1100 | | { |
| | | 1101 | | goto COMPLETE; |
| | | 1102 | | } |
| | | 1103 | | return; |
| | | 1104 | | } |
| | | 1105 | | } |
| | | 1106 | | catch (Exception ex) |
| | | 1107 | | { |
| | | 1108 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 1109 | | self.completedCount = CompleteCount; |
| | | 1110 | | self.completionSource.TrySetException(ex); |
| | | 1111 | | return; |
| | | 1112 | | } |
| | | 1113 | | |
| | | 1114 | | SUCCESS: |
| | | 1115 | | if (!self.TrySetResult()) |
| | | 1116 | | { |
| | | 1117 | | if (self.syncRunning) return; |
| | | 1118 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 1119 | | try |
| | | 1120 | | { |
| | | 1121 | | self.awaiter3 = self.enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 1122 | | } |
| | | 1123 | | catch (Exception ex) |
| | | 1124 | | { |
| | | 1125 | | self.completedCount = CompleteCount; |
| | | 1126 | | self.completionSource.TrySetException(ex); |
| | | 1127 | | return; |
| | | 1128 | | } |
| | | 1129 | | |
| | | 1130 | | self.awaiter3.SourceOnCompleted(Completed3Delegate, self); |
| | | 1131 | | } |
| | | 1132 | | return; |
| | | 1133 | | COMPLETE: |
| | | 1134 | | self.completionSource.TrySetResult(false); |
| | | 1135 | | return; |
| | | 1136 | | } |
| | | 1137 | | |
| | | 1138 | | static void Completed4(object state) |
| | | 1139 | | { |
| | | 1140 | | var self = (_CombineLatest)state; |
| | | 1141 | | self.running4 = false; |
| | | 1142 | | |
| | | 1143 | | try |
| | | 1144 | | { |
| | | 1145 | | if (self.awaiter4.GetResult()) |
| | | 1146 | | { |
| | | 1147 | | self.hasCurrent4 = true; |
| | | 1148 | | self.current4 = self.enumerator4.Current; |
| | | 1149 | | goto SUCCESS; |
| | | 1150 | | } |
| | | 1151 | | else |
| | | 1152 | | { |
| | | 1153 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 1154 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 1155 | | { |
| | | 1156 | | goto COMPLETE; |
| | | 1157 | | } |
| | | 1158 | | return; |
| | | 1159 | | } |
| | | 1160 | | } |
| | | 1161 | | catch (Exception ex) |
| | | 1162 | | { |
| | | 1163 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 1164 | | self.completedCount = CompleteCount; |
| | | 1165 | | self.completionSource.TrySetException(ex); |
| | | 1166 | | return; |
| | | 1167 | | } |
| | | 1168 | | |
| | | 1169 | | SUCCESS: |
| | | 1170 | | if (!self.TrySetResult()) |
| | | 1171 | | { |
| | | 1172 | | if (self.syncRunning) return; |
| | | 1173 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 1174 | | try |
| | | 1175 | | { |
| | | 1176 | | self.awaiter4 = self.enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 1177 | | } |
| | | 1178 | | catch (Exception ex) |
| | | 1179 | | { |
| | | 1180 | | self.completedCount = CompleteCount; |
| | | 1181 | | self.completionSource.TrySetException(ex); |
| | | 1182 | | return; |
| | | 1183 | | } |
| | | 1184 | | |
| | | 1185 | | self.awaiter4.SourceOnCompleted(Completed4Delegate, self); |
| | | 1186 | | } |
| | | 1187 | | return; |
| | | 1188 | | COMPLETE: |
| | | 1189 | | self.completionSource.TrySetResult(false); |
| | | 1190 | | return; |
| | | 1191 | | } |
| | | 1192 | | |
| | | 1193 | | bool TrySetResult() |
| | | 1194 | | { |
| | | 1195 | | if (hasCurrent1 && hasCurrent2 && hasCurrent3 && hasCurrent4) |
| | | 1196 | | { |
| | | 1197 | | result = resultSelector(current1, current2, current3, current4); |
| | | 1198 | | completionSource.TrySetResult(true); |
| | | 1199 | | return true; |
| | | 1200 | | } |
| | | 1201 | | else |
| | | 1202 | | { |
| | | 1203 | | return false; |
| | | 1204 | | } |
| | | 1205 | | } |
| | | 1206 | | |
| | | 1207 | | public async UniTask DisposeAsync() |
| | | 1208 | | { |
| | | 1209 | | TaskTracker.RemoveTracking(this); |
| | | 1210 | | if (enumerator1 != null) |
| | | 1211 | | { |
| | | 1212 | | await enumerator1.DisposeAsync(); |
| | | 1213 | | } |
| | | 1214 | | if (enumerator2 != null) |
| | | 1215 | | { |
| | | 1216 | | await enumerator2.DisposeAsync(); |
| | | 1217 | | } |
| | | 1218 | | if (enumerator3 != null) |
| | | 1219 | | { |
| | | 1220 | | await enumerator3.DisposeAsync(); |
| | | 1221 | | } |
| | | 1222 | | if (enumerator4 != null) |
| | | 1223 | | { |
| | | 1224 | | await enumerator4.DisposeAsync(); |
| | | 1225 | | } |
| | | 1226 | | } |
| | | 1227 | | } |
| | | 1228 | | } |
| | | 1229 | | |
| | | 1230 | | internal class CombineLatest<T1, T2, T3, T4, T5, TResult> : IUniTaskAsyncEnumerable<TResult> |
| | | 1231 | | { |
| | | 1232 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 1233 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 1234 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 1235 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 1236 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 1237 | | |
| | | 1238 | | readonly Func<T1, T2, T3, T4, T5, TResult> resultSelector; |
| | | 1239 | | |
| | | 1240 | | public CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyncEnum |
| | | 1241 | | { |
| | | 1242 | | this.source1 = source1; |
| | | 1243 | | this.source2 = source2; |
| | | 1244 | | this.source3 = source3; |
| | | 1245 | | this.source4 = source4; |
| | | 1246 | | this.source5 = source5; |
| | | 1247 | | |
| | | 1248 | | this.resultSelector = resultSelector; |
| | | 1249 | | } |
| | | 1250 | | |
| | | 1251 | | public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default) |
| | | 1252 | | { |
| | | 1253 | | return new _CombineLatest(source1, source2, source3, source4, source5, resultSelector, cancellationToken); |
| | | 1254 | | } |
| | | 1255 | | |
| | | 1256 | | class _CombineLatest : MoveNextSource, IUniTaskAsyncEnumerator<TResult> |
| | | 1257 | | { |
| | | 1258 | | static readonly Action<object> Completed1Delegate = Completed1; |
| | | 1259 | | static readonly Action<object> Completed2Delegate = Completed2; |
| | | 1260 | | static readonly Action<object> Completed3Delegate = Completed3; |
| | | 1261 | | static readonly Action<object> Completed4Delegate = Completed4; |
| | | 1262 | | static readonly Action<object> Completed5Delegate = Completed5; |
| | | 1263 | | const int CompleteCount = 5; |
| | | 1264 | | |
| | | 1265 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 1266 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 1267 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 1268 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 1269 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 1270 | | |
| | | 1271 | | readonly Func<T1, T2, T3, T4, T5, TResult> resultSelector; |
| | | 1272 | | CancellationToken cancellationToken; |
| | | 1273 | | |
| | | 1274 | | IUniTaskAsyncEnumerator<T1> enumerator1; |
| | | 1275 | | UniTask<bool>.Awaiter awaiter1; |
| | | 1276 | | bool hasCurrent1; |
| | | 1277 | | bool running1; |
| | | 1278 | | T1 current1; |
| | | 1279 | | |
| | | 1280 | | IUniTaskAsyncEnumerator<T2> enumerator2; |
| | | 1281 | | UniTask<bool>.Awaiter awaiter2; |
| | | 1282 | | bool hasCurrent2; |
| | | 1283 | | bool running2; |
| | | 1284 | | T2 current2; |
| | | 1285 | | |
| | | 1286 | | IUniTaskAsyncEnumerator<T3> enumerator3; |
| | | 1287 | | UniTask<bool>.Awaiter awaiter3; |
| | | 1288 | | bool hasCurrent3; |
| | | 1289 | | bool running3; |
| | | 1290 | | T3 current3; |
| | | 1291 | | |
| | | 1292 | | IUniTaskAsyncEnumerator<T4> enumerator4; |
| | | 1293 | | UniTask<bool>.Awaiter awaiter4; |
| | | 1294 | | bool hasCurrent4; |
| | | 1295 | | bool running4; |
| | | 1296 | | T4 current4; |
| | | 1297 | | |
| | | 1298 | | IUniTaskAsyncEnumerator<T5> enumerator5; |
| | | 1299 | | UniTask<bool>.Awaiter awaiter5; |
| | | 1300 | | bool hasCurrent5; |
| | | 1301 | | bool running5; |
| | | 1302 | | T5 current5; |
| | | 1303 | | |
| | | 1304 | | int completedCount; |
| | | 1305 | | bool syncRunning; |
| | | 1306 | | TResult result; |
| | | 1307 | | |
| | | 1308 | | public _CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyn |
| | | 1309 | | { |
| | | 1310 | | this.source1 = source1; |
| | | 1311 | | this.source2 = source2; |
| | | 1312 | | this.source3 = source3; |
| | | 1313 | | this.source4 = source4; |
| | | 1314 | | this.source5 = source5; |
| | | 1315 | | |
| | | 1316 | | this.resultSelector = resultSelector; |
| | | 1317 | | this.cancellationToken = cancellationToken; |
| | | 1318 | | TaskTracker.TrackActiveTask(this, 3); |
| | | 1319 | | } |
| | | 1320 | | |
| | | 1321 | | public TResult Current => result; |
| | | 1322 | | |
| | | 1323 | | public UniTask<bool> MoveNextAsync() |
| | | 1324 | | { |
| | | 1325 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 1326 | | if (completedCount == CompleteCount) return CompletedTasks.False; |
| | | 1327 | | |
| | | 1328 | | if (enumerator1 == null) |
| | | 1329 | | { |
| | | 1330 | | enumerator1 = source1.GetAsyncEnumerator(cancellationToken); |
| | | 1331 | | enumerator2 = source2.GetAsyncEnumerator(cancellationToken); |
| | | 1332 | | enumerator3 = source3.GetAsyncEnumerator(cancellationToken); |
| | | 1333 | | enumerator4 = source4.GetAsyncEnumerator(cancellationToken); |
| | | 1334 | | enumerator5 = source5.GetAsyncEnumerator(cancellationToken); |
| | | 1335 | | } |
| | | 1336 | | |
| | | 1337 | | completionSource.Reset(); |
| | | 1338 | | |
| | | 1339 | | AGAIN: |
| | | 1340 | | syncRunning = true; |
| | | 1341 | | if (!running1) |
| | | 1342 | | { |
| | | 1343 | | running1 = true; |
| | | 1344 | | awaiter1 = enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 1345 | | if (awaiter1.IsCompleted) |
| | | 1346 | | { |
| | | 1347 | | Completed1(this); |
| | | 1348 | | } |
| | | 1349 | | else |
| | | 1350 | | { |
| | | 1351 | | awaiter1.SourceOnCompleted(Completed1Delegate, this); |
| | | 1352 | | } |
| | | 1353 | | } |
| | | 1354 | | if (!running2) |
| | | 1355 | | { |
| | | 1356 | | running2 = true; |
| | | 1357 | | awaiter2 = enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 1358 | | if (awaiter2.IsCompleted) |
| | | 1359 | | { |
| | | 1360 | | Completed2(this); |
| | | 1361 | | } |
| | | 1362 | | else |
| | | 1363 | | { |
| | | 1364 | | awaiter2.SourceOnCompleted(Completed2Delegate, this); |
| | | 1365 | | } |
| | | 1366 | | } |
| | | 1367 | | if (!running3) |
| | | 1368 | | { |
| | | 1369 | | running3 = true; |
| | | 1370 | | awaiter3 = enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 1371 | | if (awaiter3.IsCompleted) |
| | | 1372 | | { |
| | | 1373 | | Completed3(this); |
| | | 1374 | | } |
| | | 1375 | | else |
| | | 1376 | | { |
| | | 1377 | | awaiter3.SourceOnCompleted(Completed3Delegate, this); |
| | | 1378 | | } |
| | | 1379 | | } |
| | | 1380 | | if (!running4) |
| | | 1381 | | { |
| | | 1382 | | running4 = true; |
| | | 1383 | | awaiter4 = enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 1384 | | if (awaiter4.IsCompleted) |
| | | 1385 | | { |
| | | 1386 | | Completed4(this); |
| | | 1387 | | } |
| | | 1388 | | else |
| | | 1389 | | { |
| | | 1390 | | awaiter4.SourceOnCompleted(Completed4Delegate, this); |
| | | 1391 | | } |
| | | 1392 | | } |
| | | 1393 | | if (!running5) |
| | | 1394 | | { |
| | | 1395 | | running5 = true; |
| | | 1396 | | awaiter5 = enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 1397 | | if (awaiter5.IsCompleted) |
| | | 1398 | | { |
| | | 1399 | | Completed5(this); |
| | | 1400 | | } |
| | | 1401 | | else |
| | | 1402 | | { |
| | | 1403 | | awaiter5.SourceOnCompleted(Completed5Delegate, this); |
| | | 1404 | | } |
| | | 1405 | | } |
| | | 1406 | | |
| | | 1407 | | if (!running1 || !running2 || !running3 || !running4 || !running5) |
| | | 1408 | | { |
| | | 1409 | | goto AGAIN; |
| | | 1410 | | } |
| | | 1411 | | syncRunning = false; |
| | | 1412 | | |
| | | 1413 | | return new UniTask<bool>(this, completionSource.Version); |
| | | 1414 | | } |
| | | 1415 | | |
| | | 1416 | | static void Completed1(object state) |
| | | 1417 | | { |
| | | 1418 | | var self = (_CombineLatest)state; |
| | | 1419 | | self.running1 = false; |
| | | 1420 | | |
| | | 1421 | | try |
| | | 1422 | | { |
| | | 1423 | | if (self.awaiter1.GetResult()) |
| | | 1424 | | { |
| | | 1425 | | self.hasCurrent1 = true; |
| | | 1426 | | self.current1 = self.enumerator1.Current; |
| | | 1427 | | goto SUCCESS; |
| | | 1428 | | } |
| | | 1429 | | else |
| | | 1430 | | { |
| | | 1431 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 1432 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 1433 | | { |
| | | 1434 | | goto COMPLETE; |
| | | 1435 | | } |
| | | 1436 | | return; |
| | | 1437 | | } |
| | | 1438 | | } |
| | | 1439 | | catch (Exception ex) |
| | | 1440 | | { |
| | | 1441 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 1442 | | self.completedCount = CompleteCount; |
| | | 1443 | | self.completionSource.TrySetException(ex); |
| | | 1444 | | return; |
| | | 1445 | | } |
| | | 1446 | | |
| | | 1447 | | SUCCESS: |
| | | 1448 | | if (!self.TrySetResult()) |
| | | 1449 | | { |
| | | 1450 | | if (self.syncRunning) return; |
| | | 1451 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 1452 | | try |
| | | 1453 | | { |
| | | 1454 | | self.awaiter1 = self.enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 1455 | | } |
| | | 1456 | | catch (Exception ex) |
| | | 1457 | | { |
| | | 1458 | | self.completedCount = CompleteCount; |
| | | 1459 | | self.completionSource.TrySetException(ex); |
| | | 1460 | | return; |
| | | 1461 | | } |
| | | 1462 | | |
| | | 1463 | | self.awaiter1.SourceOnCompleted(Completed1Delegate, self); |
| | | 1464 | | } |
| | | 1465 | | return; |
| | | 1466 | | COMPLETE: |
| | | 1467 | | self.completionSource.TrySetResult(false); |
| | | 1468 | | return; |
| | | 1469 | | } |
| | | 1470 | | |
| | | 1471 | | static void Completed2(object state) |
| | | 1472 | | { |
| | | 1473 | | var self = (_CombineLatest)state; |
| | | 1474 | | self.running2 = false; |
| | | 1475 | | |
| | | 1476 | | try |
| | | 1477 | | { |
| | | 1478 | | if (self.awaiter2.GetResult()) |
| | | 1479 | | { |
| | | 1480 | | self.hasCurrent2 = true; |
| | | 1481 | | self.current2 = self.enumerator2.Current; |
| | | 1482 | | goto SUCCESS; |
| | | 1483 | | } |
| | | 1484 | | else |
| | | 1485 | | { |
| | | 1486 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 1487 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 1488 | | { |
| | | 1489 | | goto COMPLETE; |
| | | 1490 | | } |
| | | 1491 | | return; |
| | | 1492 | | } |
| | | 1493 | | } |
| | | 1494 | | catch (Exception ex) |
| | | 1495 | | { |
| | | 1496 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 1497 | | self.completedCount = CompleteCount; |
| | | 1498 | | self.completionSource.TrySetException(ex); |
| | | 1499 | | return; |
| | | 1500 | | } |
| | | 1501 | | |
| | | 1502 | | SUCCESS: |
| | | 1503 | | if (!self.TrySetResult()) |
| | | 1504 | | { |
| | | 1505 | | if (self.syncRunning) return; |
| | | 1506 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 1507 | | try |
| | | 1508 | | { |
| | | 1509 | | self.awaiter2 = self.enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 1510 | | } |
| | | 1511 | | catch (Exception ex) |
| | | 1512 | | { |
| | | 1513 | | self.completedCount = CompleteCount; |
| | | 1514 | | self.completionSource.TrySetException(ex); |
| | | 1515 | | return; |
| | | 1516 | | } |
| | | 1517 | | |
| | | 1518 | | self.awaiter2.SourceOnCompleted(Completed2Delegate, self); |
| | | 1519 | | } |
| | | 1520 | | return; |
| | | 1521 | | COMPLETE: |
| | | 1522 | | self.completionSource.TrySetResult(false); |
| | | 1523 | | return; |
| | | 1524 | | } |
| | | 1525 | | |
| | | 1526 | | static void Completed3(object state) |
| | | 1527 | | { |
| | | 1528 | | var self = (_CombineLatest)state; |
| | | 1529 | | self.running3 = false; |
| | | 1530 | | |
| | | 1531 | | try |
| | | 1532 | | { |
| | | 1533 | | if (self.awaiter3.GetResult()) |
| | | 1534 | | { |
| | | 1535 | | self.hasCurrent3 = true; |
| | | 1536 | | self.current3 = self.enumerator3.Current; |
| | | 1537 | | goto SUCCESS; |
| | | 1538 | | } |
| | | 1539 | | else |
| | | 1540 | | { |
| | | 1541 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 1542 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 1543 | | { |
| | | 1544 | | goto COMPLETE; |
| | | 1545 | | } |
| | | 1546 | | return; |
| | | 1547 | | } |
| | | 1548 | | } |
| | | 1549 | | catch (Exception ex) |
| | | 1550 | | { |
| | | 1551 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 1552 | | self.completedCount = CompleteCount; |
| | | 1553 | | self.completionSource.TrySetException(ex); |
| | | 1554 | | return; |
| | | 1555 | | } |
| | | 1556 | | |
| | | 1557 | | SUCCESS: |
| | | 1558 | | if (!self.TrySetResult()) |
| | | 1559 | | { |
| | | 1560 | | if (self.syncRunning) return; |
| | | 1561 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 1562 | | try |
| | | 1563 | | { |
| | | 1564 | | self.awaiter3 = self.enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 1565 | | } |
| | | 1566 | | catch (Exception ex) |
| | | 1567 | | { |
| | | 1568 | | self.completedCount = CompleteCount; |
| | | 1569 | | self.completionSource.TrySetException(ex); |
| | | 1570 | | return; |
| | | 1571 | | } |
| | | 1572 | | |
| | | 1573 | | self.awaiter3.SourceOnCompleted(Completed3Delegate, self); |
| | | 1574 | | } |
| | | 1575 | | return; |
| | | 1576 | | COMPLETE: |
| | | 1577 | | self.completionSource.TrySetResult(false); |
| | | 1578 | | return; |
| | | 1579 | | } |
| | | 1580 | | |
| | | 1581 | | static void Completed4(object state) |
| | | 1582 | | { |
| | | 1583 | | var self = (_CombineLatest)state; |
| | | 1584 | | self.running4 = false; |
| | | 1585 | | |
| | | 1586 | | try |
| | | 1587 | | { |
| | | 1588 | | if (self.awaiter4.GetResult()) |
| | | 1589 | | { |
| | | 1590 | | self.hasCurrent4 = true; |
| | | 1591 | | self.current4 = self.enumerator4.Current; |
| | | 1592 | | goto SUCCESS; |
| | | 1593 | | } |
| | | 1594 | | else |
| | | 1595 | | { |
| | | 1596 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 1597 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 1598 | | { |
| | | 1599 | | goto COMPLETE; |
| | | 1600 | | } |
| | | 1601 | | return; |
| | | 1602 | | } |
| | | 1603 | | } |
| | | 1604 | | catch (Exception ex) |
| | | 1605 | | { |
| | | 1606 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 1607 | | self.completedCount = CompleteCount; |
| | | 1608 | | self.completionSource.TrySetException(ex); |
| | | 1609 | | return; |
| | | 1610 | | } |
| | | 1611 | | |
| | | 1612 | | SUCCESS: |
| | | 1613 | | if (!self.TrySetResult()) |
| | | 1614 | | { |
| | | 1615 | | if (self.syncRunning) return; |
| | | 1616 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 1617 | | try |
| | | 1618 | | { |
| | | 1619 | | self.awaiter4 = self.enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 1620 | | } |
| | | 1621 | | catch (Exception ex) |
| | | 1622 | | { |
| | | 1623 | | self.completedCount = CompleteCount; |
| | | 1624 | | self.completionSource.TrySetException(ex); |
| | | 1625 | | return; |
| | | 1626 | | } |
| | | 1627 | | |
| | | 1628 | | self.awaiter4.SourceOnCompleted(Completed4Delegate, self); |
| | | 1629 | | } |
| | | 1630 | | return; |
| | | 1631 | | COMPLETE: |
| | | 1632 | | self.completionSource.TrySetResult(false); |
| | | 1633 | | return; |
| | | 1634 | | } |
| | | 1635 | | |
| | | 1636 | | static void Completed5(object state) |
| | | 1637 | | { |
| | | 1638 | | var self = (_CombineLatest)state; |
| | | 1639 | | self.running5 = false; |
| | | 1640 | | |
| | | 1641 | | try |
| | | 1642 | | { |
| | | 1643 | | if (self.awaiter5.GetResult()) |
| | | 1644 | | { |
| | | 1645 | | self.hasCurrent5 = true; |
| | | 1646 | | self.current5 = self.enumerator5.Current; |
| | | 1647 | | goto SUCCESS; |
| | | 1648 | | } |
| | | 1649 | | else |
| | | 1650 | | { |
| | | 1651 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 1652 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 1653 | | { |
| | | 1654 | | goto COMPLETE; |
| | | 1655 | | } |
| | | 1656 | | return; |
| | | 1657 | | } |
| | | 1658 | | } |
| | | 1659 | | catch (Exception ex) |
| | | 1660 | | { |
| | | 1661 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 1662 | | self.completedCount = CompleteCount; |
| | | 1663 | | self.completionSource.TrySetException(ex); |
| | | 1664 | | return; |
| | | 1665 | | } |
| | | 1666 | | |
| | | 1667 | | SUCCESS: |
| | | 1668 | | if (!self.TrySetResult()) |
| | | 1669 | | { |
| | | 1670 | | if (self.syncRunning) return; |
| | | 1671 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 1672 | | try |
| | | 1673 | | { |
| | | 1674 | | self.awaiter5 = self.enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 1675 | | } |
| | | 1676 | | catch (Exception ex) |
| | | 1677 | | { |
| | | 1678 | | self.completedCount = CompleteCount; |
| | | 1679 | | self.completionSource.TrySetException(ex); |
| | | 1680 | | return; |
| | | 1681 | | } |
| | | 1682 | | |
| | | 1683 | | self.awaiter5.SourceOnCompleted(Completed5Delegate, self); |
| | | 1684 | | } |
| | | 1685 | | return; |
| | | 1686 | | COMPLETE: |
| | | 1687 | | self.completionSource.TrySetResult(false); |
| | | 1688 | | return; |
| | | 1689 | | } |
| | | 1690 | | |
| | | 1691 | | bool TrySetResult() |
| | | 1692 | | { |
| | | 1693 | | if (hasCurrent1 && hasCurrent2 && hasCurrent3 && hasCurrent4 && hasCurrent5) |
| | | 1694 | | { |
| | | 1695 | | result = resultSelector(current1, current2, current3, current4, current5); |
| | | 1696 | | completionSource.TrySetResult(true); |
| | | 1697 | | return true; |
| | | 1698 | | } |
| | | 1699 | | else |
| | | 1700 | | { |
| | | 1701 | | return false; |
| | | 1702 | | } |
| | | 1703 | | } |
| | | 1704 | | |
| | | 1705 | | public async UniTask DisposeAsync() |
| | | 1706 | | { |
| | | 1707 | | TaskTracker.RemoveTracking(this); |
| | | 1708 | | if (enumerator1 != null) |
| | | 1709 | | { |
| | | 1710 | | await enumerator1.DisposeAsync(); |
| | | 1711 | | } |
| | | 1712 | | if (enumerator2 != null) |
| | | 1713 | | { |
| | | 1714 | | await enumerator2.DisposeAsync(); |
| | | 1715 | | } |
| | | 1716 | | if (enumerator3 != null) |
| | | 1717 | | { |
| | | 1718 | | await enumerator3.DisposeAsync(); |
| | | 1719 | | } |
| | | 1720 | | if (enumerator4 != null) |
| | | 1721 | | { |
| | | 1722 | | await enumerator4.DisposeAsync(); |
| | | 1723 | | } |
| | | 1724 | | if (enumerator5 != null) |
| | | 1725 | | { |
| | | 1726 | | await enumerator5.DisposeAsync(); |
| | | 1727 | | } |
| | | 1728 | | } |
| | | 1729 | | } |
| | | 1730 | | } |
| | | 1731 | | |
| | | 1732 | | internal class CombineLatest<T1, T2, T3, T4, T5, T6, TResult> : IUniTaskAsyncEnumerable<TResult> |
| | | 1733 | | { |
| | | 1734 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 1735 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 1736 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 1737 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 1738 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 1739 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 1740 | | |
| | | 1741 | | readonly Func<T1, T2, T3, T4, T5, T6, TResult> resultSelector; |
| | | 1742 | | |
| | | 1743 | | public CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyncEnum |
| | | 1744 | | { |
| | | 1745 | | this.source1 = source1; |
| | | 1746 | | this.source2 = source2; |
| | | 1747 | | this.source3 = source3; |
| | | 1748 | | this.source4 = source4; |
| | | 1749 | | this.source5 = source5; |
| | | 1750 | | this.source6 = source6; |
| | | 1751 | | |
| | | 1752 | | this.resultSelector = resultSelector; |
| | | 1753 | | } |
| | | 1754 | | |
| | | 1755 | | public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default) |
| | | 1756 | | { |
| | | 1757 | | return new _CombineLatest(source1, source2, source3, source4, source5, source6, resultSelector, cancellation |
| | | 1758 | | } |
| | | 1759 | | |
| | | 1760 | | class _CombineLatest : MoveNextSource, IUniTaskAsyncEnumerator<TResult> |
| | | 1761 | | { |
| | | 1762 | | static readonly Action<object> Completed1Delegate = Completed1; |
| | | 1763 | | static readonly Action<object> Completed2Delegate = Completed2; |
| | | 1764 | | static readonly Action<object> Completed3Delegate = Completed3; |
| | | 1765 | | static readonly Action<object> Completed4Delegate = Completed4; |
| | | 1766 | | static readonly Action<object> Completed5Delegate = Completed5; |
| | | 1767 | | static readonly Action<object> Completed6Delegate = Completed6; |
| | | 1768 | | const int CompleteCount = 6; |
| | | 1769 | | |
| | | 1770 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 1771 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 1772 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 1773 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 1774 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 1775 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 1776 | | |
| | | 1777 | | readonly Func<T1, T2, T3, T4, T5, T6, TResult> resultSelector; |
| | | 1778 | | CancellationToken cancellationToken; |
| | | 1779 | | |
| | | 1780 | | IUniTaskAsyncEnumerator<T1> enumerator1; |
| | | 1781 | | UniTask<bool>.Awaiter awaiter1; |
| | | 1782 | | bool hasCurrent1; |
| | | 1783 | | bool running1; |
| | | 1784 | | T1 current1; |
| | | 1785 | | |
| | | 1786 | | IUniTaskAsyncEnumerator<T2> enumerator2; |
| | | 1787 | | UniTask<bool>.Awaiter awaiter2; |
| | | 1788 | | bool hasCurrent2; |
| | | 1789 | | bool running2; |
| | | 1790 | | T2 current2; |
| | | 1791 | | |
| | | 1792 | | IUniTaskAsyncEnumerator<T3> enumerator3; |
| | | 1793 | | UniTask<bool>.Awaiter awaiter3; |
| | | 1794 | | bool hasCurrent3; |
| | | 1795 | | bool running3; |
| | | 1796 | | T3 current3; |
| | | 1797 | | |
| | | 1798 | | IUniTaskAsyncEnumerator<T4> enumerator4; |
| | | 1799 | | UniTask<bool>.Awaiter awaiter4; |
| | | 1800 | | bool hasCurrent4; |
| | | 1801 | | bool running4; |
| | | 1802 | | T4 current4; |
| | | 1803 | | |
| | | 1804 | | IUniTaskAsyncEnumerator<T5> enumerator5; |
| | | 1805 | | UniTask<bool>.Awaiter awaiter5; |
| | | 1806 | | bool hasCurrent5; |
| | | 1807 | | bool running5; |
| | | 1808 | | T5 current5; |
| | | 1809 | | |
| | | 1810 | | IUniTaskAsyncEnumerator<T6> enumerator6; |
| | | 1811 | | UniTask<bool>.Awaiter awaiter6; |
| | | 1812 | | bool hasCurrent6; |
| | | 1813 | | bool running6; |
| | | 1814 | | T6 current6; |
| | | 1815 | | |
| | | 1816 | | int completedCount; |
| | | 1817 | | bool syncRunning; |
| | | 1818 | | TResult result; |
| | | 1819 | | |
| | | 1820 | | public _CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyn |
| | | 1821 | | { |
| | | 1822 | | this.source1 = source1; |
| | | 1823 | | this.source2 = source2; |
| | | 1824 | | this.source3 = source3; |
| | | 1825 | | this.source4 = source4; |
| | | 1826 | | this.source5 = source5; |
| | | 1827 | | this.source6 = source6; |
| | | 1828 | | |
| | | 1829 | | this.resultSelector = resultSelector; |
| | | 1830 | | this.cancellationToken = cancellationToken; |
| | | 1831 | | TaskTracker.TrackActiveTask(this, 3); |
| | | 1832 | | } |
| | | 1833 | | |
| | | 1834 | | public TResult Current => result; |
| | | 1835 | | |
| | | 1836 | | public UniTask<bool> MoveNextAsync() |
| | | 1837 | | { |
| | | 1838 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 1839 | | if (completedCount == CompleteCount) return CompletedTasks.False; |
| | | 1840 | | |
| | | 1841 | | if (enumerator1 == null) |
| | | 1842 | | { |
| | | 1843 | | enumerator1 = source1.GetAsyncEnumerator(cancellationToken); |
| | | 1844 | | enumerator2 = source2.GetAsyncEnumerator(cancellationToken); |
| | | 1845 | | enumerator3 = source3.GetAsyncEnumerator(cancellationToken); |
| | | 1846 | | enumerator4 = source4.GetAsyncEnumerator(cancellationToken); |
| | | 1847 | | enumerator5 = source5.GetAsyncEnumerator(cancellationToken); |
| | | 1848 | | enumerator6 = source6.GetAsyncEnumerator(cancellationToken); |
| | | 1849 | | } |
| | | 1850 | | |
| | | 1851 | | completionSource.Reset(); |
| | | 1852 | | |
| | | 1853 | | AGAIN: |
| | | 1854 | | syncRunning = true; |
| | | 1855 | | if (!running1) |
| | | 1856 | | { |
| | | 1857 | | running1 = true; |
| | | 1858 | | awaiter1 = enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 1859 | | if (awaiter1.IsCompleted) |
| | | 1860 | | { |
| | | 1861 | | Completed1(this); |
| | | 1862 | | } |
| | | 1863 | | else |
| | | 1864 | | { |
| | | 1865 | | awaiter1.SourceOnCompleted(Completed1Delegate, this); |
| | | 1866 | | } |
| | | 1867 | | } |
| | | 1868 | | if (!running2) |
| | | 1869 | | { |
| | | 1870 | | running2 = true; |
| | | 1871 | | awaiter2 = enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 1872 | | if (awaiter2.IsCompleted) |
| | | 1873 | | { |
| | | 1874 | | Completed2(this); |
| | | 1875 | | } |
| | | 1876 | | else |
| | | 1877 | | { |
| | | 1878 | | awaiter2.SourceOnCompleted(Completed2Delegate, this); |
| | | 1879 | | } |
| | | 1880 | | } |
| | | 1881 | | if (!running3) |
| | | 1882 | | { |
| | | 1883 | | running3 = true; |
| | | 1884 | | awaiter3 = enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 1885 | | if (awaiter3.IsCompleted) |
| | | 1886 | | { |
| | | 1887 | | Completed3(this); |
| | | 1888 | | } |
| | | 1889 | | else |
| | | 1890 | | { |
| | | 1891 | | awaiter3.SourceOnCompleted(Completed3Delegate, this); |
| | | 1892 | | } |
| | | 1893 | | } |
| | | 1894 | | if (!running4) |
| | | 1895 | | { |
| | | 1896 | | running4 = true; |
| | | 1897 | | awaiter4 = enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 1898 | | if (awaiter4.IsCompleted) |
| | | 1899 | | { |
| | | 1900 | | Completed4(this); |
| | | 1901 | | } |
| | | 1902 | | else |
| | | 1903 | | { |
| | | 1904 | | awaiter4.SourceOnCompleted(Completed4Delegate, this); |
| | | 1905 | | } |
| | | 1906 | | } |
| | | 1907 | | if (!running5) |
| | | 1908 | | { |
| | | 1909 | | running5 = true; |
| | | 1910 | | awaiter5 = enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 1911 | | if (awaiter5.IsCompleted) |
| | | 1912 | | { |
| | | 1913 | | Completed5(this); |
| | | 1914 | | } |
| | | 1915 | | else |
| | | 1916 | | { |
| | | 1917 | | awaiter5.SourceOnCompleted(Completed5Delegate, this); |
| | | 1918 | | } |
| | | 1919 | | } |
| | | 1920 | | if (!running6) |
| | | 1921 | | { |
| | | 1922 | | running6 = true; |
| | | 1923 | | awaiter6 = enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 1924 | | if (awaiter6.IsCompleted) |
| | | 1925 | | { |
| | | 1926 | | Completed6(this); |
| | | 1927 | | } |
| | | 1928 | | else |
| | | 1929 | | { |
| | | 1930 | | awaiter6.SourceOnCompleted(Completed6Delegate, this); |
| | | 1931 | | } |
| | | 1932 | | } |
| | | 1933 | | |
| | | 1934 | | if (!running1 || !running2 || !running3 || !running4 || !running5 || !running6) |
| | | 1935 | | { |
| | | 1936 | | goto AGAIN; |
| | | 1937 | | } |
| | | 1938 | | syncRunning = false; |
| | | 1939 | | |
| | | 1940 | | return new UniTask<bool>(this, completionSource.Version); |
| | | 1941 | | } |
| | | 1942 | | |
| | | 1943 | | static void Completed1(object state) |
| | | 1944 | | { |
| | | 1945 | | var self = (_CombineLatest)state; |
| | | 1946 | | self.running1 = false; |
| | | 1947 | | |
| | | 1948 | | try |
| | | 1949 | | { |
| | | 1950 | | if (self.awaiter1.GetResult()) |
| | | 1951 | | { |
| | | 1952 | | self.hasCurrent1 = true; |
| | | 1953 | | self.current1 = self.enumerator1.Current; |
| | | 1954 | | goto SUCCESS; |
| | | 1955 | | } |
| | | 1956 | | else |
| | | 1957 | | { |
| | | 1958 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 1959 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 1960 | | { |
| | | 1961 | | goto COMPLETE; |
| | | 1962 | | } |
| | | 1963 | | return; |
| | | 1964 | | } |
| | | 1965 | | } |
| | | 1966 | | catch (Exception ex) |
| | | 1967 | | { |
| | | 1968 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 1969 | | self.completedCount = CompleteCount; |
| | | 1970 | | self.completionSource.TrySetException(ex); |
| | | 1971 | | return; |
| | | 1972 | | } |
| | | 1973 | | |
| | | 1974 | | SUCCESS: |
| | | 1975 | | if (!self.TrySetResult()) |
| | | 1976 | | { |
| | | 1977 | | if (self.syncRunning) return; |
| | | 1978 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 1979 | | try |
| | | 1980 | | { |
| | | 1981 | | self.awaiter1 = self.enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 1982 | | } |
| | | 1983 | | catch (Exception ex) |
| | | 1984 | | { |
| | | 1985 | | self.completedCount = CompleteCount; |
| | | 1986 | | self.completionSource.TrySetException(ex); |
| | | 1987 | | return; |
| | | 1988 | | } |
| | | 1989 | | |
| | | 1990 | | self.awaiter1.SourceOnCompleted(Completed1Delegate, self); |
| | | 1991 | | } |
| | | 1992 | | return; |
| | | 1993 | | COMPLETE: |
| | | 1994 | | self.completionSource.TrySetResult(false); |
| | | 1995 | | return; |
| | | 1996 | | } |
| | | 1997 | | |
| | | 1998 | | static void Completed2(object state) |
| | | 1999 | | { |
| | | 2000 | | var self = (_CombineLatest)state; |
| | | 2001 | | self.running2 = false; |
| | | 2002 | | |
| | | 2003 | | try |
| | | 2004 | | { |
| | | 2005 | | if (self.awaiter2.GetResult()) |
| | | 2006 | | { |
| | | 2007 | | self.hasCurrent2 = true; |
| | | 2008 | | self.current2 = self.enumerator2.Current; |
| | | 2009 | | goto SUCCESS; |
| | | 2010 | | } |
| | | 2011 | | else |
| | | 2012 | | { |
| | | 2013 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 2014 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 2015 | | { |
| | | 2016 | | goto COMPLETE; |
| | | 2017 | | } |
| | | 2018 | | return; |
| | | 2019 | | } |
| | | 2020 | | } |
| | | 2021 | | catch (Exception ex) |
| | | 2022 | | { |
| | | 2023 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 2024 | | self.completedCount = CompleteCount; |
| | | 2025 | | self.completionSource.TrySetException(ex); |
| | | 2026 | | return; |
| | | 2027 | | } |
| | | 2028 | | |
| | | 2029 | | SUCCESS: |
| | | 2030 | | if (!self.TrySetResult()) |
| | | 2031 | | { |
| | | 2032 | | if (self.syncRunning) return; |
| | | 2033 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 2034 | | try |
| | | 2035 | | { |
| | | 2036 | | self.awaiter2 = self.enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 2037 | | } |
| | | 2038 | | catch (Exception ex) |
| | | 2039 | | { |
| | | 2040 | | self.completedCount = CompleteCount; |
| | | 2041 | | self.completionSource.TrySetException(ex); |
| | | 2042 | | return; |
| | | 2043 | | } |
| | | 2044 | | |
| | | 2045 | | self.awaiter2.SourceOnCompleted(Completed2Delegate, self); |
| | | 2046 | | } |
| | | 2047 | | return; |
| | | 2048 | | COMPLETE: |
| | | 2049 | | self.completionSource.TrySetResult(false); |
| | | 2050 | | return; |
| | | 2051 | | } |
| | | 2052 | | |
| | | 2053 | | static void Completed3(object state) |
| | | 2054 | | { |
| | | 2055 | | var self = (_CombineLatest)state; |
| | | 2056 | | self.running3 = false; |
| | | 2057 | | |
| | | 2058 | | try |
| | | 2059 | | { |
| | | 2060 | | if (self.awaiter3.GetResult()) |
| | | 2061 | | { |
| | | 2062 | | self.hasCurrent3 = true; |
| | | 2063 | | self.current3 = self.enumerator3.Current; |
| | | 2064 | | goto SUCCESS; |
| | | 2065 | | } |
| | | 2066 | | else |
| | | 2067 | | { |
| | | 2068 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 2069 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 2070 | | { |
| | | 2071 | | goto COMPLETE; |
| | | 2072 | | } |
| | | 2073 | | return; |
| | | 2074 | | } |
| | | 2075 | | } |
| | | 2076 | | catch (Exception ex) |
| | | 2077 | | { |
| | | 2078 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 2079 | | self.completedCount = CompleteCount; |
| | | 2080 | | self.completionSource.TrySetException(ex); |
| | | 2081 | | return; |
| | | 2082 | | } |
| | | 2083 | | |
| | | 2084 | | SUCCESS: |
| | | 2085 | | if (!self.TrySetResult()) |
| | | 2086 | | { |
| | | 2087 | | if (self.syncRunning) return; |
| | | 2088 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 2089 | | try |
| | | 2090 | | { |
| | | 2091 | | self.awaiter3 = self.enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 2092 | | } |
| | | 2093 | | catch (Exception ex) |
| | | 2094 | | { |
| | | 2095 | | self.completedCount = CompleteCount; |
| | | 2096 | | self.completionSource.TrySetException(ex); |
| | | 2097 | | return; |
| | | 2098 | | } |
| | | 2099 | | |
| | | 2100 | | self.awaiter3.SourceOnCompleted(Completed3Delegate, self); |
| | | 2101 | | } |
| | | 2102 | | return; |
| | | 2103 | | COMPLETE: |
| | | 2104 | | self.completionSource.TrySetResult(false); |
| | | 2105 | | return; |
| | | 2106 | | } |
| | | 2107 | | |
| | | 2108 | | static void Completed4(object state) |
| | | 2109 | | { |
| | | 2110 | | var self = (_CombineLatest)state; |
| | | 2111 | | self.running4 = false; |
| | | 2112 | | |
| | | 2113 | | try |
| | | 2114 | | { |
| | | 2115 | | if (self.awaiter4.GetResult()) |
| | | 2116 | | { |
| | | 2117 | | self.hasCurrent4 = true; |
| | | 2118 | | self.current4 = self.enumerator4.Current; |
| | | 2119 | | goto SUCCESS; |
| | | 2120 | | } |
| | | 2121 | | else |
| | | 2122 | | { |
| | | 2123 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 2124 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 2125 | | { |
| | | 2126 | | goto COMPLETE; |
| | | 2127 | | } |
| | | 2128 | | return; |
| | | 2129 | | } |
| | | 2130 | | } |
| | | 2131 | | catch (Exception ex) |
| | | 2132 | | { |
| | | 2133 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 2134 | | self.completedCount = CompleteCount; |
| | | 2135 | | self.completionSource.TrySetException(ex); |
| | | 2136 | | return; |
| | | 2137 | | } |
| | | 2138 | | |
| | | 2139 | | SUCCESS: |
| | | 2140 | | if (!self.TrySetResult()) |
| | | 2141 | | { |
| | | 2142 | | if (self.syncRunning) return; |
| | | 2143 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 2144 | | try |
| | | 2145 | | { |
| | | 2146 | | self.awaiter4 = self.enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 2147 | | } |
| | | 2148 | | catch (Exception ex) |
| | | 2149 | | { |
| | | 2150 | | self.completedCount = CompleteCount; |
| | | 2151 | | self.completionSource.TrySetException(ex); |
| | | 2152 | | return; |
| | | 2153 | | } |
| | | 2154 | | |
| | | 2155 | | self.awaiter4.SourceOnCompleted(Completed4Delegate, self); |
| | | 2156 | | } |
| | | 2157 | | return; |
| | | 2158 | | COMPLETE: |
| | | 2159 | | self.completionSource.TrySetResult(false); |
| | | 2160 | | return; |
| | | 2161 | | } |
| | | 2162 | | |
| | | 2163 | | static void Completed5(object state) |
| | | 2164 | | { |
| | | 2165 | | var self = (_CombineLatest)state; |
| | | 2166 | | self.running5 = false; |
| | | 2167 | | |
| | | 2168 | | try |
| | | 2169 | | { |
| | | 2170 | | if (self.awaiter5.GetResult()) |
| | | 2171 | | { |
| | | 2172 | | self.hasCurrent5 = true; |
| | | 2173 | | self.current5 = self.enumerator5.Current; |
| | | 2174 | | goto SUCCESS; |
| | | 2175 | | } |
| | | 2176 | | else |
| | | 2177 | | { |
| | | 2178 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 2179 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 2180 | | { |
| | | 2181 | | goto COMPLETE; |
| | | 2182 | | } |
| | | 2183 | | return; |
| | | 2184 | | } |
| | | 2185 | | } |
| | | 2186 | | catch (Exception ex) |
| | | 2187 | | { |
| | | 2188 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 2189 | | self.completedCount = CompleteCount; |
| | | 2190 | | self.completionSource.TrySetException(ex); |
| | | 2191 | | return; |
| | | 2192 | | } |
| | | 2193 | | |
| | | 2194 | | SUCCESS: |
| | | 2195 | | if (!self.TrySetResult()) |
| | | 2196 | | { |
| | | 2197 | | if (self.syncRunning) return; |
| | | 2198 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 2199 | | try |
| | | 2200 | | { |
| | | 2201 | | self.awaiter5 = self.enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 2202 | | } |
| | | 2203 | | catch (Exception ex) |
| | | 2204 | | { |
| | | 2205 | | self.completedCount = CompleteCount; |
| | | 2206 | | self.completionSource.TrySetException(ex); |
| | | 2207 | | return; |
| | | 2208 | | } |
| | | 2209 | | |
| | | 2210 | | self.awaiter5.SourceOnCompleted(Completed5Delegate, self); |
| | | 2211 | | } |
| | | 2212 | | return; |
| | | 2213 | | COMPLETE: |
| | | 2214 | | self.completionSource.TrySetResult(false); |
| | | 2215 | | return; |
| | | 2216 | | } |
| | | 2217 | | |
| | | 2218 | | static void Completed6(object state) |
| | | 2219 | | { |
| | | 2220 | | var self = (_CombineLatest)state; |
| | | 2221 | | self.running6 = false; |
| | | 2222 | | |
| | | 2223 | | try |
| | | 2224 | | { |
| | | 2225 | | if (self.awaiter6.GetResult()) |
| | | 2226 | | { |
| | | 2227 | | self.hasCurrent6 = true; |
| | | 2228 | | self.current6 = self.enumerator6.Current; |
| | | 2229 | | goto SUCCESS; |
| | | 2230 | | } |
| | | 2231 | | else |
| | | 2232 | | { |
| | | 2233 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 2234 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 2235 | | { |
| | | 2236 | | goto COMPLETE; |
| | | 2237 | | } |
| | | 2238 | | return; |
| | | 2239 | | } |
| | | 2240 | | } |
| | | 2241 | | catch (Exception ex) |
| | | 2242 | | { |
| | | 2243 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 2244 | | self.completedCount = CompleteCount; |
| | | 2245 | | self.completionSource.TrySetException(ex); |
| | | 2246 | | return; |
| | | 2247 | | } |
| | | 2248 | | |
| | | 2249 | | SUCCESS: |
| | | 2250 | | if (!self.TrySetResult()) |
| | | 2251 | | { |
| | | 2252 | | if (self.syncRunning) return; |
| | | 2253 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 2254 | | try |
| | | 2255 | | { |
| | | 2256 | | self.awaiter6 = self.enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 2257 | | } |
| | | 2258 | | catch (Exception ex) |
| | | 2259 | | { |
| | | 2260 | | self.completedCount = CompleteCount; |
| | | 2261 | | self.completionSource.TrySetException(ex); |
| | | 2262 | | return; |
| | | 2263 | | } |
| | | 2264 | | |
| | | 2265 | | self.awaiter6.SourceOnCompleted(Completed6Delegate, self); |
| | | 2266 | | } |
| | | 2267 | | return; |
| | | 2268 | | COMPLETE: |
| | | 2269 | | self.completionSource.TrySetResult(false); |
| | | 2270 | | return; |
| | | 2271 | | } |
| | | 2272 | | |
| | | 2273 | | bool TrySetResult() |
| | | 2274 | | { |
| | | 2275 | | if (hasCurrent1 && hasCurrent2 && hasCurrent3 && hasCurrent4 && hasCurrent5 && hasCurrent6) |
| | | 2276 | | { |
| | | 2277 | | result = resultSelector(current1, current2, current3, current4, current5, current6); |
| | | 2278 | | completionSource.TrySetResult(true); |
| | | 2279 | | return true; |
| | | 2280 | | } |
| | | 2281 | | else |
| | | 2282 | | { |
| | | 2283 | | return false; |
| | | 2284 | | } |
| | | 2285 | | } |
| | | 2286 | | |
| | | 2287 | | public async UniTask DisposeAsync() |
| | | 2288 | | { |
| | | 2289 | | TaskTracker.RemoveTracking(this); |
| | | 2290 | | if (enumerator1 != null) |
| | | 2291 | | { |
| | | 2292 | | await enumerator1.DisposeAsync(); |
| | | 2293 | | } |
| | | 2294 | | if (enumerator2 != null) |
| | | 2295 | | { |
| | | 2296 | | await enumerator2.DisposeAsync(); |
| | | 2297 | | } |
| | | 2298 | | if (enumerator3 != null) |
| | | 2299 | | { |
| | | 2300 | | await enumerator3.DisposeAsync(); |
| | | 2301 | | } |
| | | 2302 | | if (enumerator4 != null) |
| | | 2303 | | { |
| | | 2304 | | await enumerator4.DisposeAsync(); |
| | | 2305 | | } |
| | | 2306 | | if (enumerator5 != null) |
| | | 2307 | | { |
| | | 2308 | | await enumerator5.DisposeAsync(); |
| | | 2309 | | } |
| | | 2310 | | if (enumerator6 != null) |
| | | 2311 | | { |
| | | 2312 | | await enumerator6.DisposeAsync(); |
| | | 2313 | | } |
| | | 2314 | | } |
| | | 2315 | | } |
| | | 2316 | | } |
| | | 2317 | | |
| | | 2318 | | internal class CombineLatest<T1, T2, T3, T4, T5, T6, T7, TResult> : IUniTaskAsyncEnumerable<TResult> |
| | | 2319 | | { |
| | | 2320 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 2321 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 2322 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 2323 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 2324 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 2325 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 2326 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 2327 | | |
| | | 2328 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, TResult> resultSelector; |
| | | 2329 | | |
| | | 2330 | | public CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyncEnum |
| | | 2331 | | { |
| | | 2332 | | this.source1 = source1; |
| | | 2333 | | this.source2 = source2; |
| | | 2334 | | this.source3 = source3; |
| | | 2335 | | this.source4 = source4; |
| | | 2336 | | this.source5 = source5; |
| | | 2337 | | this.source6 = source6; |
| | | 2338 | | this.source7 = source7; |
| | | 2339 | | |
| | | 2340 | | this.resultSelector = resultSelector; |
| | | 2341 | | } |
| | | 2342 | | |
| | | 2343 | | public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default) |
| | | 2344 | | { |
| | | 2345 | | return new _CombineLatest(source1, source2, source3, source4, source5, source6, source7, resultSelector, can |
| | | 2346 | | } |
| | | 2347 | | |
| | | 2348 | | class _CombineLatest : MoveNextSource, IUniTaskAsyncEnumerator<TResult> |
| | | 2349 | | { |
| | | 2350 | | static readonly Action<object> Completed1Delegate = Completed1; |
| | | 2351 | | static readonly Action<object> Completed2Delegate = Completed2; |
| | | 2352 | | static readonly Action<object> Completed3Delegate = Completed3; |
| | | 2353 | | static readonly Action<object> Completed4Delegate = Completed4; |
| | | 2354 | | static readonly Action<object> Completed5Delegate = Completed5; |
| | | 2355 | | static readonly Action<object> Completed6Delegate = Completed6; |
| | | 2356 | | static readonly Action<object> Completed7Delegate = Completed7; |
| | | 2357 | | const int CompleteCount = 7; |
| | | 2358 | | |
| | | 2359 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 2360 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 2361 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 2362 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 2363 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 2364 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 2365 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 2366 | | |
| | | 2367 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, TResult> resultSelector; |
| | | 2368 | | CancellationToken cancellationToken; |
| | | 2369 | | |
| | | 2370 | | IUniTaskAsyncEnumerator<T1> enumerator1; |
| | | 2371 | | UniTask<bool>.Awaiter awaiter1; |
| | | 2372 | | bool hasCurrent1; |
| | | 2373 | | bool running1; |
| | | 2374 | | T1 current1; |
| | | 2375 | | |
| | | 2376 | | IUniTaskAsyncEnumerator<T2> enumerator2; |
| | | 2377 | | UniTask<bool>.Awaiter awaiter2; |
| | | 2378 | | bool hasCurrent2; |
| | | 2379 | | bool running2; |
| | | 2380 | | T2 current2; |
| | | 2381 | | |
| | | 2382 | | IUniTaskAsyncEnumerator<T3> enumerator3; |
| | | 2383 | | UniTask<bool>.Awaiter awaiter3; |
| | | 2384 | | bool hasCurrent3; |
| | | 2385 | | bool running3; |
| | | 2386 | | T3 current3; |
| | | 2387 | | |
| | | 2388 | | IUniTaskAsyncEnumerator<T4> enumerator4; |
| | | 2389 | | UniTask<bool>.Awaiter awaiter4; |
| | | 2390 | | bool hasCurrent4; |
| | | 2391 | | bool running4; |
| | | 2392 | | T4 current4; |
| | | 2393 | | |
| | | 2394 | | IUniTaskAsyncEnumerator<T5> enumerator5; |
| | | 2395 | | UniTask<bool>.Awaiter awaiter5; |
| | | 2396 | | bool hasCurrent5; |
| | | 2397 | | bool running5; |
| | | 2398 | | T5 current5; |
| | | 2399 | | |
| | | 2400 | | IUniTaskAsyncEnumerator<T6> enumerator6; |
| | | 2401 | | UniTask<bool>.Awaiter awaiter6; |
| | | 2402 | | bool hasCurrent6; |
| | | 2403 | | bool running6; |
| | | 2404 | | T6 current6; |
| | | 2405 | | |
| | | 2406 | | IUniTaskAsyncEnumerator<T7> enumerator7; |
| | | 2407 | | UniTask<bool>.Awaiter awaiter7; |
| | | 2408 | | bool hasCurrent7; |
| | | 2409 | | bool running7; |
| | | 2410 | | T7 current7; |
| | | 2411 | | |
| | | 2412 | | int completedCount; |
| | | 2413 | | bool syncRunning; |
| | | 2414 | | TResult result; |
| | | 2415 | | |
| | | 2416 | | public _CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyn |
| | | 2417 | | { |
| | | 2418 | | this.source1 = source1; |
| | | 2419 | | this.source2 = source2; |
| | | 2420 | | this.source3 = source3; |
| | | 2421 | | this.source4 = source4; |
| | | 2422 | | this.source5 = source5; |
| | | 2423 | | this.source6 = source6; |
| | | 2424 | | this.source7 = source7; |
| | | 2425 | | |
| | | 2426 | | this.resultSelector = resultSelector; |
| | | 2427 | | this.cancellationToken = cancellationToken; |
| | | 2428 | | TaskTracker.TrackActiveTask(this, 3); |
| | | 2429 | | } |
| | | 2430 | | |
| | | 2431 | | public TResult Current => result; |
| | | 2432 | | |
| | | 2433 | | public UniTask<bool> MoveNextAsync() |
| | | 2434 | | { |
| | | 2435 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 2436 | | if (completedCount == CompleteCount) return CompletedTasks.False; |
| | | 2437 | | |
| | | 2438 | | if (enumerator1 == null) |
| | | 2439 | | { |
| | | 2440 | | enumerator1 = source1.GetAsyncEnumerator(cancellationToken); |
| | | 2441 | | enumerator2 = source2.GetAsyncEnumerator(cancellationToken); |
| | | 2442 | | enumerator3 = source3.GetAsyncEnumerator(cancellationToken); |
| | | 2443 | | enumerator4 = source4.GetAsyncEnumerator(cancellationToken); |
| | | 2444 | | enumerator5 = source5.GetAsyncEnumerator(cancellationToken); |
| | | 2445 | | enumerator6 = source6.GetAsyncEnumerator(cancellationToken); |
| | | 2446 | | enumerator7 = source7.GetAsyncEnumerator(cancellationToken); |
| | | 2447 | | } |
| | | 2448 | | |
| | | 2449 | | completionSource.Reset(); |
| | | 2450 | | |
| | | 2451 | | AGAIN: |
| | | 2452 | | syncRunning = true; |
| | | 2453 | | if (!running1) |
| | | 2454 | | { |
| | | 2455 | | running1 = true; |
| | | 2456 | | awaiter1 = enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 2457 | | if (awaiter1.IsCompleted) |
| | | 2458 | | { |
| | | 2459 | | Completed1(this); |
| | | 2460 | | } |
| | | 2461 | | else |
| | | 2462 | | { |
| | | 2463 | | awaiter1.SourceOnCompleted(Completed1Delegate, this); |
| | | 2464 | | } |
| | | 2465 | | } |
| | | 2466 | | if (!running2) |
| | | 2467 | | { |
| | | 2468 | | running2 = true; |
| | | 2469 | | awaiter2 = enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 2470 | | if (awaiter2.IsCompleted) |
| | | 2471 | | { |
| | | 2472 | | Completed2(this); |
| | | 2473 | | } |
| | | 2474 | | else |
| | | 2475 | | { |
| | | 2476 | | awaiter2.SourceOnCompleted(Completed2Delegate, this); |
| | | 2477 | | } |
| | | 2478 | | } |
| | | 2479 | | if (!running3) |
| | | 2480 | | { |
| | | 2481 | | running3 = true; |
| | | 2482 | | awaiter3 = enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 2483 | | if (awaiter3.IsCompleted) |
| | | 2484 | | { |
| | | 2485 | | Completed3(this); |
| | | 2486 | | } |
| | | 2487 | | else |
| | | 2488 | | { |
| | | 2489 | | awaiter3.SourceOnCompleted(Completed3Delegate, this); |
| | | 2490 | | } |
| | | 2491 | | } |
| | | 2492 | | if (!running4) |
| | | 2493 | | { |
| | | 2494 | | running4 = true; |
| | | 2495 | | awaiter4 = enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 2496 | | if (awaiter4.IsCompleted) |
| | | 2497 | | { |
| | | 2498 | | Completed4(this); |
| | | 2499 | | } |
| | | 2500 | | else |
| | | 2501 | | { |
| | | 2502 | | awaiter4.SourceOnCompleted(Completed4Delegate, this); |
| | | 2503 | | } |
| | | 2504 | | } |
| | | 2505 | | if (!running5) |
| | | 2506 | | { |
| | | 2507 | | running5 = true; |
| | | 2508 | | awaiter5 = enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 2509 | | if (awaiter5.IsCompleted) |
| | | 2510 | | { |
| | | 2511 | | Completed5(this); |
| | | 2512 | | } |
| | | 2513 | | else |
| | | 2514 | | { |
| | | 2515 | | awaiter5.SourceOnCompleted(Completed5Delegate, this); |
| | | 2516 | | } |
| | | 2517 | | } |
| | | 2518 | | if (!running6) |
| | | 2519 | | { |
| | | 2520 | | running6 = true; |
| | | 2521 | | awaiter6 = enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 2522 | | if (awaiter6.IsCompleted) |
| | | 2523 | | { |
| | | 2524 | | Completed6(this); |
| | | 2525 | | } |
| | | 2526 | | else |
| | | 2527 | | { |
| | | 2528 | | awaiter6.SourceOnCompleted(Completed6Delegate, this); |
| | | 2529 | | } |
| | | 2530 | | } |
| | | 2531 | | if (!running7) |
| | | 2532 | | { |
| | | 2533 | | running7 = true; |
| | | 2534 | | awaiter7 = enumerator7.MoveNextAsync().GetAwaiter(); |
| | | 2535 | | if (awaiter7.IsCompleted) |
| | | 2536 | | { |
| | | 2537 | | Completed7(this); |
| | | 2538 | | } |
| | | 2539 | | else |
| | | 2540 | | { |
| | | 2541 | | awaiter7.SourceOnCompleted(Completed7Delegate, this); |
| | | 2542 | | } |
| | | 2543 | | } |
| | | 2544 | | |
| | | 2545 | | if (!running1 || !running2 || !running3 || !running4 || !running5 || !running6 || !running7) |
| | | 2546 | | { |
| | | 2547 | | goto AGAIN; |
| | | 2548 | | } |
| | | 2549 | | syncRunning = false; |
| | | 2550 | | |
| | | 2551 | | return new UniTask<bool>(this, completionSource.Version); |
| | | 2552 | | } |
| | | 2553 | | |
| | | 2554 | | static void Completed1(object state) |
| | | 2555 | | { |
| | | 2556 | | var self = (_CombineLatest)state; |
| | | 2557 | | self.running1 = false; |
| | | 2558 | | |
| | | 2559 | | try |
| | | 2560 | | { |
| | | 2561 | | if (self.awaiter1.GetResult()) |
| | | 2562 | | { |
| | | 2563 | | self.hasCurrent1 = true; |
| | | 2564 | | self.current1 = self.enumerator1.Current; |
| | | 2565 | | goto SUCCESS; |
| | | 2566 | | } |
| | | 2567 | | else |
| | | 2568 | | { |
| | | 2569 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 2570 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 2571 | | { |
| | | 2572 | | goto COMPLETE; |
| | | 2573 | | } |
| | | 2574 | | return; |
| | | 2575 | | } |
| | | 2576 | | } |
| | | 2577 | | catch (Exception ex) |
| | | 2578 | | { |
| | | 2579 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 2580 | | self.completedCount = CompleteCount; |
| | | 2581 | | self.completionSource.TrySetException(ex); |
| | | 2582 | | return; |
| | | 2583 | | } |
| | | 2584 | | |
| | | 2585 | | SUCCESS: |
| | | 2586 | | if (!self.TrySetResult()) |
| | | 2587 | | { |
| | | 2588 | | if (self.syncRunning) return; |
| | | 2589 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 2590 | | try |
| | | 2591 | | { |
| | | 2592 | | self.awaiter1 = self.enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 2593 | | } |
| | | 2594 | | catch (Exception ex) |
| | | 2595 | | { |
| | | 2596 | | self.completedCount = CompleteCount; |
| | | 2597 | | self.completionSource.TrySetException(ex); |
| | | 2598 | | return; |
| | | 2599 | | } |
| | | 2600 | | |
| | | 2601 | | self.awaiter1.SourceOnCompleted(Completed1Delegate, self); |
| | | 2602 | | } |
| | | 2603 | | return; |
| | | 2604 | | COMPLETE: |
| | | 2605 | | self.completionSource.TrySetResult(false); |
| | | 2606 | | return; |
| | | 2607 | | } |
| | | 2608 | | |
| | | 2609 | | static void Completed2(object state) |
| | | 2610 | | { |
| | | 2611 | | var self = (_CombineLatest)state; |
| | | 2612 | | self.running2 = false; |
| | | 2613 | | |
| | | 2614 | | try |
| | | 2615 | | { |
| | | 2616 | | if (self.awaiter2.GetResult()) |
| | | 2617 | | { |
| | | 2618 | | self.hasCurrent2 = true; |
| | | 2619 | | self.current2 = self.enumerator2.Current; |
| | | 2620 | | goto SUCCESS; |
| | | 2621 | | } |
| | | 2622 | | else |
| | | 2623 | | { |
| | | 2624 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 2625 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 2626 | | { |
| | | 2627 | | goto COMPLETE; |
| | | 2628 | | } |
| | | 2629 | | return; |
| | | 2630 | | } |
| | | 2631 | | } |
| | | 2632 | | catch (Exception ex) |
| | | 2633 | | { |
| | | 2634 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 2635 | | self.completedCount = CompleteCount; |
| | | 2636 | | self.completionSource.TrySetException(ex); |
| | | 2637 | | return; |
| | | 2638 | | } |
| | | 2639 | | |
| | | 2640 | | SUCCESS: |
| | | 2641 | | if (!self.TrySetResult()) |
| | | 2642 | | { |
| | | 2643 | | if (self.syncRunning) return; |
| | | 2644 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 2645 | | try |
| | | 2646 | | { |
| | | 2647 | | self.awaiter2 = self.enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 2648 | | } |
| | | 2649 | | catch (Exception ex) |
| | | 2650 | | { |
| | | 2651 | | self.completedCount = CompleteCount; |
| | | 2652 | | self.completionSource.TrySetException(ex); |
| | | 2653 | | return; |
| | | 2654 | | } |
| | | 2655 | | |
| | | 2656 | | self.awaiter2.SourceOnCompleted(Completed2Delegate, self); |
| | | 2657 | | } |
| | | 2658 | | return; |
| | | 2659 | | COMPLETE: |
| | | 2660 | | self.completionSource.TrySetResult(false); |
| | | 2661 | | return; |
| | | 2662 | | } |
| | | 2663 | | |
| | | 2664 | | static void Completed3(object state) |
| | | 2665 | | { |
| | | 2666 | | var self = (_CombineLatest)state; |
| | | 2667 | | self.running3 = false; |
| | | 2668 | | |
| | | 2669 | | try |
| | | 2670 | | { |
| | | 2671 | | if (self.awaiter3.GetResult()) |
| | | 2672 | | { |
| | | 2673 | | self.hasCurrent3 = true; |
| | | 2674 | | self.current3 = self.enumerator3.Current; |
| | | 2675 | | goto SUCCESS; |
| | | 2676 | | } |
| | | 2677 | | else |
| | | 2678 | | { |
| | | 2679 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 2680 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 2681 | | { |
| | | 2682 | | goto COMPLETE; |
| | | 2683 | | } |
| | | 2684 | | return; |
| | | 2685 | | } |
| | | 2686 | | } |
| | | 2687 | | catch (Exception ex) |
| | | 2688 | | { |
| | | 2689 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 2690 | | self.completedCount = CompleteCount; |
| | | 2691 | | self.completionSource.TrySetException(ex); |
| | | 2692 | | return; |
| | | 2693 | | } |
| | | 2694 | | |
| | | 2695 | | SUCCESS: |
| | | 2696 | | if (!self.TrySetResult()) |
| | | 2697 | | { |
| | | 2698 | | if (self.syncRunning) return; |
| | | 2699 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 2700 | | try |
| | | 2701 | | { |
| | | 2702 | | self.awaiter3 = self.enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 2703 | | } |
| | | 2704 | | catch (Exception ex) |
| | | 2705 | | { |
| | | 2706 | | self.completedCount = CompleteCount; |
| | | 2707 | | self.completionSource.TrySetException(ex); |
| | | 2708 | | return; |
| | | 2709 | | } |
| | | 2710 | | |
| | | 2711 | | self.awaiter3.SourceOnCompleted(Completed3Delegate, self); |
| | | 2712 | | } |
| | | 2713 | | return; |
| | | 2714 | | COMPLETE: |
| | | 2715 | | self.completionSource.TrySetResult(false); |
| | | 2716 | | return; |
| | | 2717 | | } |
| | | 2718 | | |
| | | 2719 | | static void Completed4(object state) |
| | | 2720 | | { |
| | | 2721 | | var self = (_CombineLatest)state; |
| | | 2722 | | self.running4 = false; |
| | | 2723 | | |
| | | 2724 | | try |
| | | 2725 | | { |
| | | 2726 | | if (self.awaiter4.GetResult()) |
| | | 2727 | | { |
| | | 2728 | | self.hasCurrent4 = true; |
| | | 2729 | | self.current4 = self.enumerator4.Current; |
| | | 2730 | | goto SUCCESS; |
| | | 2731 | | } |
| | | 2732 | | else |
| | | 2733 | | { |
| | | 2734 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 2735 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 2736 | | { |
| | | 2737 | | goto COMPLETE; |
| | | 2738 | | } |
| | | 2739 | | return; |
| | | 2740 | | } |
| | | 2741 | | } |
| | | 2742 | | catch (Exception ex) |
| | | 2743 | | { |
| | | 2744 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 2745 | | self.completedCount = CompleteCount; |
| | | 2746 | | self.completionSource.TrySetException(ex); |
| | | 2747 | | return; |
| | | 2748 | | } |
| | | 2749 | | |
| | | 2750 | | SUCCESS: |
| | | 2751 | | if (!self.TrySetResult()) |
| | | 2752 | | { |
| | | 2753 | | if (self.syncRunning) return; |
| | | 2754 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 2755 | | try |
| | | 2756 | | { |
| | | 2757 | | self.awaiter4 = self.enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 2758 | | } |
| | | 2759 | | catch (Exception ex) |
| | | 2760 | | { |
| | | 2761 | | self.completedCount = CompleteCount; |
| | | 2762 | | self.completionSource.TrySetException(ex); |
| | | 2763 | | return; |
| | | 2764 | | } |
| | | 2765 | | |
| | | 2766 | | self.awaiter4.SourceOnCompleted(Completed4Delegate, self); |
| | | 2767 | | } |
| | | 2768 | | return; |
| | | 2769 | | COMPLETE: |
| | | 2770 | | self.completionSource.TrySetResult(false); |
| | | 2771 | | return; |
| | | 2772 | | } |
| | | 2773 | | |
| | | 2774 | | static void Completed5(object state) |
| | | 2775 | | { |
| | | 2776 | | var self = (_CombineLatest)state; |
| | | 2777 | | self.running5 = false; |
| | | 2778 | | |
| | | 2779 | | try |
| | | 2780 | | { |
| | | 2781 | | if (self.awaiter5.GetResult()) |
| | | 2782 | | { |
| | | 2783 | | self.hasCurrent5 = true; |
| | | 2784 | | self.current5 = self.enumerator5.Current; |
| | | 2785 | | goto SUCCESS; |
| | | 2786 | | } |
| | | 2787 | | else |
| | | 2788 | | { |
| | | 2789 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 2790 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 2791 | | { |
| | | 2792 | | goto COMPLETE; |
| | | 2793 | | } |
| | | 2794 | | return; |
| | | 2795 | | } |
| | | 2796 | | } |
| | | 2797 | | catch (Exception ex) |
| | | 2798 | | { |
| | | 2799 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 2800 | | self.completedCount = CompleteCount; |
| | | 2801 | | self.completionSource.TrySetException(ex); |
| | | 2802 | | return; |
| | | 2803 | | } |
| | | 2804 | | |
| | | 2805 | | SUCCESS: |
| | | 2806 | | if (!self.TrySetResult()) |
| | | 2807 | | { |
| | | 2808 | | if (self.syncRunning) return; |
| | | 2809 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 2810 | | try |
| | | 2811 | | { |
| | | 2812 | | self.awaiter5 = self.enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 2813 | | } |
| | | 2814 | | catch (Exception ex) |
| | | 2815 | | { |
| | | 2816 | | self.completedCount = CompleteCount; |
| | | 2817 | | self.completionSource.TrySetException(ex); |
| | | 2818 | | return; |
| | | 2819 | | } |
| | | 2820 | | |
| | | 2821 | | self.awaiter5.SourceOnCompleted(Completed5Delegate, self); |
| | | 2822 | | } |
| | | 2823 | | return; |
| | | 2824 | | COMPLETE: |
| | | 2825 | | self.completionSource.TrySetResult(false); |
| | | 2826 | | return; |
| | | 2827 | | } |
| | | 2828 | | |
| | | 2829 | | static void Completed6(object state) |
| | | 2830 | | { |
| | | 2831 | | var self = (_CombineLatest)state; |
| | | 2832 | | self.running6 = false; |
| | | 2833 | | |
| | | 2834 | | try |
| | | 2835 | | { |
| | | 2836 | | if (self.awaiter6.GetResult()) |
| | | 2837 | | { |
| | | 2838 | | self.hasCurrent6 = true; |
| | | 2839 | | self.current6 = self.enumerator6.Current; |
| | | 2840 | | goto SUCCESS; |
| | | 2841 | | } |
| | | 2842 | | else |
| | | 2843 | | { |
| | | 2844 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 2845 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 2846 | | { |
| | | 2847 | | goto COMPLETE; |
| | | 2848 | | } |
| | | 2849 | | return; |
| | | 2850 | | } |
| | | 2851 | | } |
| | | 2852 | | catch (Exception ex) |
| | | 2853 | | { |
| | | 2854 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 2855 | | self.completedCount = CompleteCount; |
| | | 2856 | | self.completionSource.TrySetException(ex); |
| | | 2857 | | return; |
| | | 2858 | | } |
| | | 2859 | | |
| | | 2860 | | SUCCESS: |
| | | 2861 | | if (!self.TrySetResult()) |
| | | 2862 | | { |
| | | 2863 | | if (self.syncRunning) return; |
| | | 2864 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 2865 | | try |
| | | 2866 | | { |
| | | 2867 | | self.awaiter6 = self.enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 2868 | | } |
| | | 2869 | | catch (Exception ex) |
| | | 2870 | | { |
| | | 2871 | | self.completedCount = CompleteCount; |
| | | 2872 | | self.completionSource.TrySetException(ex); |
| | | 2873 | | return; |
| | | 2874 | | } |
| | | 2875 | | |
| | | 2876 | | self.awaiter6.SourceOnCompleted(Completed6Delegate, self); |
| | | 2877 | | } |
| | | 2878 | | return; |
| | | 2879 | | COMPLETE: |
| | | 2880 | | self.completionSource.TrySetResult(false); |
| | | 2881 | | return; |
| | | 2882 | | } |
| | | 2883 | | |
| | | 2884 | | static void Completed7(object state) |
| | | 2885 | | { |
| | | 2886 | | var self = (_CombineLatest)state; |
| | | 2887 | | self.running7 = false; |
| | | 2888 | | |
| | | 2889 | | try |
| | | 2890 | | { |
| | | 2891 | | if (self.awaiter7.GetResult()) |
| | | 2892 | | { |
| | | 2893 | | self.hasCurrent7 = true; |
| | | 2894 | | self.current7 = self.enumerator7.Current; |
| | | 2895 | | goto SUCCESS; |
| | | 2896 | | } |
| | | 2897 | | else |
| | | 2898 | | { |
| | | 2899 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 2900 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 2901 | | { |
| | | 2902 | | goto COMPLETE; |
| | | 2903 | | } |
| | | 2904 | | return; |
| | | 2905 | | } |
| | | 2906 | | } |
| | | 2907 | | catch (Exception ex) |
| | | 2908 | | { |
| | | 2909 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 2910 | | self.completedCount = CompleteCount; |
| | | 2911 | | self.completionSource.TrySetException(ex); |
| | | 2912 | | return; |
| | | 2913 | | } |
| | | 2914 | | |
| | | 2915 | | SUCCESS: |
| | | 2916 | | if (!self.TrySetResult()) |
| | | 2917 | | { |
| | | 2918 | | if (self.syncRunning) return; |
| | | 2919 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 2920 | | try |
| | | 2921 | | { |
| | | 2922 | | self.awaiter7 = self.enumerator7.MoveNextAsync().GetAwaiter(); |
| | | 2923 | | } |
| | | 2924 | | catch (Exception ex) |
| | | 2925 | | { |
| | | 2926 | | self.completedCount = CompleteCount; |
| | | 2927 | | self.completionSource.TrySetException(ex); |
| | | 2928 | | return; |
| | | 2929 | | } |
| | | 2930 | | |
| | | 2931 | | self.awaiter7.SourceOnCompleted(Completed7Delegate, self); |
| | | 2932 | | } |
| | | 2933 | | return; |
| | | 2934 | | COMPLETE: |
| | | 2935 | | self.completionSource.TrySetResult(false); |
| | | 2936 | | return; |
| | | 2937 | | } |
| | | 2938 | | |
| | | 2939 | | bool TrySetResult() |
| | | 2940 | | { |
| | | 2941 | | if (hasCurrent1 && hasCurrent2 && hasCurrent3 && hasCurrent4 && hasCurrent5 && hasCurrent6 && hasCurrent |
| | | 2942 | | { |
| | | 2943 | | result = resultSelector(current1, current2, current3, current4, current5, current6, current7); |
| | | 2944 | | completionSource.TrySetResult(true); |
| | | 2945 | | return true; |
| | | 2946 | | } |
| | | 2947 | | else |
| | | 2948 | | { |
| | | 2949 | | return false; |
| | | 2950 | | } |
| | | 2951 | | } |
| | | 2952 | | |
| | | 2953 | | public async UniTask DisposeAsync() |
| | | 2954 | | { |
| | | 2955 | | TaskTracker.RemoveTracking(this); |
| | | 2956 | | if (enumerator1 != null) |
| | | 2957 | | { |
| | | 2958 | | await enumerator1.DisposeAsync(); |
| | | 2959 | | } |
| | | 2960 | | if (enumerator2 != null) |
| | | 2961 | | { |
| | | 2962 | | await enumerator2.DisposeAsync(); |
| | | 2963 | | } |
| | | 2964 | | if (enumerator3 != null) |
| | | 2965 | | { |
| | | 2966 | | await enumerator3.DisposeAsync(); |
| | | 2967 | | } |
| | | 2968 | | if (enumerator4 != null) |
| | | 2969 | | { |
| | | 2970 | | await enumerator4.DisposeAsync(); |
| | | 2971 | | } |
| | | 2972 | | if (enumerator5 != null) |
| | | 2973 | | { |
| | | 2974 | | await enumerator5.DisposeAsync(); |
| | | 2975 | | } |
| | | 2976 | | if (enumerator6 != null) |
| | | 2977 | | { |
| | | 2978 | | await enumerator6.DisposeAsync(); |
| | | 2979 | | } |
| | | 2980 | | if (enumerator7 != null) |
| | | 2981 | | { |
| | | 2982 | | await enumerator7.DisposeAsync(); |
| | | 2983 | | } |
| | | 2984 | | } |
| | | 2985 | | } |
| | | 2986 | | } |
| | | 2987 | | |
| | | 2988 | | internal class CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, TResult> : IUniTaskAsyncEnumerable<TResult> |
| | | 2989 | | { |
| | | 2990 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 2991 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 2992 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 2993 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 2994 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 2995 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 2996 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 2997 | | readonly IUniTaskAsyncEnumerable<T8> source8; |
| | | 2998 | | |
| | | 2999 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> resultSelector; |
| | | 3000 | | |
| | | 3001 | | public CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyncEnum |
| | | 3002 | | { |
| | | 3003 | | this.source1 = source1; |
| | | 3004 | | this.source2 = source2; |
| | | 3005 | | this.source3 = source3; |
| | | 3006 | | this.source4 = source4; |
| | | 3007 | | this.source5 = source5; |
| | | 3008 | | this.source6 = source6; |
| | | 3009 | | this.source7 = source7; |
| | | 3010 | | this.source8 = source8; |
| | | 3011 | | |
| | | 3012 | | this.resultSelector = resultSelector; |
| | | 3013 | | } |
| | | 3014 | | |
| | | 3015 | | public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default) |
| | | 3016 | | { |
| | | 3017 | | return new _CombineLatest(source1, source2, source3, source4, source5, source6, source7, source8, resultSele |
| | | 3018 | | } |
| | | 3019 | | |
| | | 3020 | | class _CombineLatest : MoveNextSource, IUniTaskAsyncEnumerator<TResult> |
| | | 3021 | | { |
| | | 3022 | | static readonly Action<object> Completed1Delegate = Completed1; |
| | | 3023 | | static readonly Action<object> Completed2Delegate = Completed2; |
| | | 3024 | | static readonly Action<object> Completed3Delegate = Completed3; |
| | | 3025 | | static readonly Action<object> Completed4Delegate = Completed4; |
| | | 3026 | | static readonly Action<object> Completed5Delegate = Completed5; |
| | | 3027 | | static readonly Action<object> Completed6Delegate = Completed6; |
| | | 3028 | | static readonly Action<object> Completed7Delegate = Completed7; |
| | | 3029 | | static readonly Action<object> Completed8Delegate = Completed8; |
| | | 3030 | | const int CompleteCount = 8; |
| | | 3031 | | |
| | | 3032 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 3033 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 3034 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 3035 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 3036 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 3037 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 3038 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 3039 | | readonly IUniTaskAsyncEnumerable<T8> source8; |
| | | 3040 | | |
| | | 3041 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> resultSelector; |
| | | 3042 | | CancellationToken cancellationToken; |
| | | 3043 | | |
| | | 3044 | | IUniTaskAsyncEnumerator<T1> enumerator1; |
| | | 3045 | | UniTask<bool>.Awaiter awaiter1; |
| | | 3046 | | bool hasCurrent1; |
| | | 3047 | | bool running1; |
| | | 3048 | | T1 current1; |
| | | 3049 | | |
| | | 3050 | | IUniTaskAsyncEnumerator<T2> enumerator2; |
| | | 3051 | | UniTask<bool>.Awaiter awaiter2; |
| | | 3052 | | bool hasCurrent2; |
| | | 3053 | | bool running2; |
| | | 3054 | | T2 current2; |
| | | 3055 | | |
| | | 3056 | | IUniTaskAsyncEnumerator<T3> enumerator3; |
| | | 3057 | | UniTask<bool>.Awaiter awaiter3; |
| | | 3058 | | bool hasCurrent3; |
| | | 3059 | | bool running3; |
| | | 3060 | | T3 current3; |
| | | 3061 | | |
| | | 3062 | | IUniTaskAsyncEnumerator<T4> enumerator4; |
| | | 3063 | | UniTask<bool>.Awaiter awaiter4; |
| | | 3064 | | bool hasCurrent4; |
| | | 3065 | | bool running4; |
| | | 3066 | | T4 current4; |
| | | 3067 | | |
| | | 3068 | | IUniTaskAsyncEnumerator<T5> enumerator5; |
| | | 3069 | | UniTask<bool>.Awaiter awaiter5; |
| | | 3070 | | bool hasCurrent5; |
| | | 3071 | | bool running5; |
| | | 3072 | | T5 current5; |
| | | 3073 | | |
| | | 3074 | | IUniTaskAsyncEnumerator<T6> enumerator6; |
| | | 3075 | | UniTask<bool>.Awaiter awaiter6; |
| | | 3076 | | bool hasCurrent6; |
| | | 3077 | | bool running6; |
| | | 3078 | | T6 current6; |
| | | 3079 | | |
| | | 3080 | | IUniTaskAsyncEnumerator<T7> enumerator7; |
| | | 3081 | | UniTask<bool>.Awaiter awaiter7; |
| | | 3082 | | bool hasCurrent7; |
| | | 3083 | | bool running7; |
| | | 3084 | | T7 current7; |
| | | 3085 | | |
| | | 3086 | | IUniTaskAsyncEnumerator<T8> enumerator8; |
| | | 3087 | | UniTask<bool>.Awaiter awaiter8; |
| | | 3088 | | bool hasCurrent8; |
| | | 3089 | | bool running8; |
| | | 3090 | | T8 current8; |
| | | 3091 | | |
| | | 3092 | | int completedCount; |
| | | 3093 | | bool syncRunning; |
| | | 3094 | | TResult result; |
| | | 3095 | | |
| | | 3096 | | public _CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyn |
| | | 3097 | | { |
| | | 3098 | | this.source1 = source1; |
| | | 3099 | | this.source2 = source2; |
| | | 3100 | | this.source3 = source3; |
| | | 3101 | | this.source4 = source4; |
| | | 3102 | | this.source5 = source5; |
| | | 3103 | | this.source6 = source6; |
| | | 3104 | | this.source7 = source7; |
| | | 3105 | | this.source8 = source8; |
| | | 3106 | | |
| | | 3107 | | this.resultSelector = resultSelector; |
| | | 3108 | | this.cancellationToken = cancellationToken; |
| | | 3109 | | TaskTracker.TrackActiveTask(this, 3); |
| | | 3110 | | } |
| | | 3111 | | |
| | | 3112 | | public TResult Current => result; |
| | | 3113 | | |
| | | 3114 | | public UniTask<bool> MoveNextAsync() |
| | | 3115 | | { |
| | | 3116 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 3117 | | if (completedCount == CompleteCount) return CompletedTasks.False; |
| | | 3118 | | |
| | | 3119 | | if (enumerator1 == null) |
| | | 3120 | | { |
| | | 3121 | | enumerator1 = source1.GetAsyncEnumerator(cancellationToken); |
| | | 3122 | | enumerator2 = source2.GetAsyncEnumerator(cancellationToken); |
| | | 3123 | | enumerator3 = source3.GetAsyncEnumerator(cancellationToken); |
| | | 3124 | | enumerator4 = source4.GetAsyncEnumerator(cancellationToken); |
| | | 3125 | | enumerator5 = source5.GetAsyncEnumerator(cancellationToken); |
| | | 3126 | | enumerator6 = source6.GetAsyncEnumerator(cancellationToken); |
| | | 3127 | | enumerator7 = source7.GetAsyncEnumerator(cancellationToken); |
| | | 3128 | | enumerator8 = source8.GetAsyncEnumerator(cancellationToken); |
| | | 3129 | | } |
| | | 3130 | | |
| | | 3131 | | completionSource.Reset(); |
| | | 3132 | | |
| | | 3133 | | AGAIN: |
| | | 3134 | | syncRunning = true; |
| | | 3135 | | if (!running1) |
| | | 3136 | | { |
| | | 3137 | | running1 = true; |
| | | 3138 | | awaiter1 = enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 3139 | | if (awaiter1.IsCompleted) |
| | | 3140 | | { |
| | | 3141 | | Completed1(this); |
| | | 3142 | | } |
| | | 3143 | | else |
| | | 3144 | | { |
| | | 3145 | | awaiter1.SourceOnCompleted(Completed1Delegate, this); |
| | | 3146 | | } |
| | | 3147 | | } |
| | | 3148 | | if (!running2) |
| | | 3149 | | { |
| | | 3150 | | running2 = true; |
| | | 3151 | | awaiter2 = enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 3152 | | if (awaiter2.IsCompleted) |
| | | 3153 | | { |
| | | 3154 | | Completed2(this); |
| | | 3155 | | } |
| | | 3156 | | else |
| | | 3157 | | { |
| | | 3158 | | awaiter2.SourceOnCompleted(Completed2Delegate, this); |
| | | 3159 | | } |
| | | 3160 | | } |
| | | 3161 | | if (!running3) |
| | | 3162 | | { |
| | | 3163 | | running3 = true; |
| | | 3164 | | awaiter3 = enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 3165 | | if (awaiter3.IsCompleted) |
| | | 3166 | | { |
| | | 3167 | | Completed3(this); |
| | | 3168 | | } |
| | | 3169 | | else |
| | | 3170 | | { |
| | | 3171 | | awaiter3.SourceOnCompleted(Completed3Delegate, this); |
| | | 3172 | | } |
| | | 3173 | | } |
| | | 3174 | | if (!running4) |
| | | 3175 | | { |
| | | 3176 | | running4 = true; |
| | | 3177 | | awaiter4 = enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 3178 | | if (awaiter4.IsCompleted) |
| | | 3179 | | { |
| | | 3180 | | Completed4(this); |
| | | 3181 | | } |
| | | 3182 | | else |
| | | 3183 | | { |
| | | 3184 | | awaiter4.SourceOnCompleted(Completed4Delegate, this); |
| | | 3185 | | } |
| | | 3186 | | } |
| | | 3187 | | if (!running5) |
| | | 3188 | | { |
| | | 3189 | | running5 = true; |
| | | 3190 | | awaiter5 = enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 3191 | | if (awaiter5.IsCompleted) |
| | | 3192 | | { |
| | | 3193 | | Completed5(this); |
| | | 3194 | | } |
| | | 3195 | | else |
| | | 3196 | | { |
| | | 3197 | | awaiter5.SourceOnCompleted(Completed5Delegate, this); |
| | | 3198 | | } |
| | | 3199 | | } |
| | | 3200 | | if (!running6) |
| | | 3201 | | { |
| | | 3202 | | running6 = true; |
| | | 3203 | | awaiter6 = enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 3204 | | if (awaiter6.IsCompleted) |
| | | 3205 | | { |
| | | 3206 | | Completed6(this); |
| | | 3207 | | } |
| | | 3208 | | else |
| | | 3209 | | { |
| | | 3210 | | awaiter6.SourceOnCompleted(Completed6Delegate, this); |
| | | 3211 | | } |
| | | 3212 | | } |
| | | 3213 | | if (!running7) |
| | | 3214 | | { |
| | | 3215 | | running7 = true; |
| | | 3216 | | awaiter7 = enumerator7.MoveNextAsync().GetAwaiter(); |
| | | 3217 | | if (awaiter7.IsCompleted) |
| | | 3218 | | { |
| | | 3219 | | Completed7(this); |
| | | 3220 | | } |
| | | 3221 | | else |
| | | 3222 | | { |
| | | 3223 | | awaiter7.SourceOnCompleted(Completed7Delegate, this); |
| | | 3224 | | } |
| | | 3225 | | } |
| | | 3226 | | if (!running8) |
| | | 3227 | | { |
| | | 3228 | | running8 = true; |
| | | 3229 | | awaiter8 = enumerator8.MoveNextAsync().GetAwaiter(); |
| | | 3230 | | if (awaiter8.IsCompleted) |
| | | 3231 | | { |
| | | 3232 | | Completed8(this); |
| | | 3233 | | } |
| | | 3234 | | else |
| | | 3235 | | { |
| | | 3236 | | awaiter8.SourceOnCompleted(Completed8Delegate, this); |
| | | 3237 | | } |
| | | 3238 | | } |
| | | 3239 | | |
| | | 3240 | | if (!running1 || !running2 || !running3 || !running4 || !running5 || !running6 || !running7 || !running8 |
| | | 3241 | | { |
| | | 3242 | | goto AGAIN; |
| | | 3243 | | } |
| | | 3244 | | syncRunning = false; |
| | | 3245 | | |
| | | 3246 | | return new UniTask<bool>(this, completionSource.Version); |
| | | 3247 | | } |
| | | 3248 | | |
| | | 3249 | | static void Completed1(object state) |
| | | 3250 | | { |
| | | 3251 | | var self = (_CombineLatest)state; |
| | | 3252 | | self.running1 = false; |
| | | 3253 | | |
| | | 3254 | | try |
| | | 3255 | | { |
| | | 3256 | | if (self.awaiter1.GetResult()) |
| | | 3257 | | { |
| | | 3258 | | self.hasCurrent1 = true; |
| | | 3259 | | self.current1 = self.enumerator1.Current; |
| | | 3260 | | goto SUCCESS; |
| | | 3261 | | } |
| | | 3262 | | else |
| | | 3263 | | { |
| | | 3264 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 3265 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 3266 | | { |
| | | 3267 | | goto COMPLETE; |
| | | 3268 | | } |
| | | 3269 | | return; |
| | | 3270 | | } |
| | | 3271 | | } |
| | | 3272 | | catch (Exception ex) |
| | | 3273 | | { |
| | | 3274 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 3275 | | self.completedCount = CompleteCount; |
| | | 3276 | | self.completionSource.TrySetException(ex); |
| | | 3277 | | return; |
| | | 3278 | | } |
| | | 3279 | | |
| | | 3280 | | SUCCESS: |
| | | 3281 | | if (!self.TrySetResult()) |
| | | 3282 | | { |
| | | 3283 | | if (self.syncRunning) return; |
| | | 3284 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 3285 | | try |
| | | 3286 | | { |
| | | 3287 | | self.awaiter1 = self.enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 3288 | | } |
| | | 3289 | | catch (Exception ex) |
| | | 3290 | | { |
| | | 3291 | | self.completedCount = CompleteCount; |
| | | 3292 | | self.completionSource.TrySetException(ex); |
| | | 3293 | | return; |
| | | 3294 | | } |
| | | 3295 | | |
| | | 3296 | | self.awaiter1.SourceOnCompleted(Completed1Delegate, self); |
| | | 3297 | | } |
| | | 3298 | | return; |
| | | 3299 | | COMPLETE: |
| | | 3300 | | self.completionSource.TrySetResult(false); |
| | | 3301 | | return; |
| | | 3302 | | } |
| | | 3303 | | |
| | | 3304 | | static void Completed2(object state) |
| | | 3305 | | { |
| | | 3306 | | var self = (_CombineLatest)state; |
| | | 3307 | | self.running2 = false; |
| | | 3308 | | |
| | | 3309 | | try |
| | | 3310 | | { |
| | | 3311 | | if (self.awaiter2.GetResult()) |
| | | 3312 | | { |
| | | 3313 | | self.hasCurrent2 = true; |
| | | 3314 | | self.current2 = self.enumerator2.Current; |
| | | 3315 | | goto SUCCESS; |
| | | 3316 | | } |
| | | 3317 | | else |
| | | 3318 | | { |
| | | 3319 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 3320 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 3321 | | { |
| | | 3322 | | goto COMPLETE; |
| | | 3323 | | } |
| | | 3324 | | return; |
| | | 3325 | | } |
| | | 3326 | | } |
| | | 3327 | | catch (Exception ex) |
| | | 3328 | | { |
| | | 3329 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 3330 | | self.completedCount = CompleteCount; |
| | | 3331 | | self.completionSource.TrySetException(ex); |
| | | 3332 | | return; |
| | | 3333 | | } |
| | | 3334 | | |
| | | 3335 | | SUCCESS: |
| | | 3336 | | if (!self.TrySetResult()) |
| | | 3337 | | { |
| | | 3338 | | if (self.syncRunning) return; |
| | | 3339 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 3340 | | try |
| | | 3341 | | { |
| | | 3342 | | self.awaiter2 = self.enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 3343 | | } |
| | | 3344 | | catch (Exception ex) |
| | | 3345 | | { |
| | | 3346 | | self.completedCount = CompleteCount; |
| | | 3347 | | self.completionSource.TrySetException(ex); |
| | | 3348 | | return; |
| | | 3349 | | } |
| | | 3350 | | |
| | | 3351 | | self.awaiter2.SourceOnCompleted(Completed2Delegate, self); |
| | | 3352 | | } |
| | | 3353 | | return; |
| | | 3354 | | COMPLETE: |
| | | 3355 | | self.completionSource.TrySetResult(false); |
| | | 3356 | | return; |
| | | 3357 | | } |
| | | 3358 | | |
| | | 3359 | | static void Completed3(object state) |
| | | 3360 | | { |
| | | 3361 | | var self = (_CombineLatest)state; |
| | | 3362 | | self.running3 = false; |
| | | 3363 | | |
| | | 3364 | | try |
| | | 3365 | | { |
| | | 3366 | | if (self.awaiter3.GetResult()) |
| | | 3367 | | { |
| | | 3368 | | self.hasCurrent3 = true; |
| | | 3369 | | self.current3 = self.enumerator3.Current; |
| | | 3370 | | goto SUCCESS; |
| | | 3371 | | } |
| | | 3372 | | else |
| | | 3373 | | { |
| | | 3374 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 3375 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 3376 | | { |
| | | 3377 | | goto COMPLETE; |
| | | 3378 | | } |
| | | 3379 | | return; |
| | | 3380 | | } |
| | | 3381 | | } |
| | | 3382 | | catch (Exception ex) |
| | | 3383 | | { |
| | | 3384 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 3385 | | self.completedCount = CompleteCount; |
| | | 3386 | | self.completionSource.TrySetException(ex); |
| | | 3387 | | return; |
| | | 3388 | | } |
| | | 3389 | | |
| | | 3390 | | SUCCESS: |
| | | 3391 | | if (!self.TrySetResult()) |
| | | 3392 | | { |
| | | 3393 | | if (self.syncRunning) return; |
| | | 3394 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 3395 | | try |
| | | 3396 | | { |
| | | 3397 | | self.awaiter3 = self.enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 3398 | | } |
| | | 3399 | | catch (Exception ex) |
| | | 3400 | | { |
| | | 3401 | | self.completedCount = CompleteCount; |
| | | 3402 | | self.completionSource.TrySetException(ex); |
| | | 3403 | | return; |
| | | 3404 | | } |
| | | 3405 | | |
| | | 3406 | | self.awaiter3.SourceOnCompleted(Completed3Delegate, self); |
| | | 3407 | | } |
| | | 3408 | | return; |
| | | 3409 | | COMPLETE: |
| | | 3410 | | self.completionSource.TrySetResult(false); |
| | | 3411 | | return; |
| | | 3412 | | } |
| | | 3413 | | |
| | | 3414 | | static void Completed4(object state) |
| | | 3415 | | { |
| | | 3416 | | var self = (_CombineLatest)state; |
| | | 3417 | | self.running4 = false; |
| | | 3418 | | |
| | | 3419 | | try |
| | | 3420 | | { |
| | | 3421 | | if (self.awaiter4.GetResult()) |
| | | 3422 | | { |
| | | 3423 | | self.hasCurrent4 = true; |
| | | 3424 | | self.current4 = self.enumerator4.Current; |
| | | 3425 | | goto SUCCESS; |
| | | 3426 | | } |
| | | 3427 | | else |
| | | 3428 | | { |
| | | 3429 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 3430 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 3431 | | { |
| | | 3432 | | goto COMPLETE; |
| | | 3433 | | } |
| | | 3434 | | return; |
| | | 3435 | | } |
| | | 3436 | | } |
| | | 3437 | | catch (Exception ex) |
| | | 3438 | | { |
| | | 3439 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 3440 | | self.completedCount = CompleteCount; |
| | | 3441 | | self.completionSource.TrySetException(ex); |
| | | 3442 | | return; |
| | | 3443 | | } |
| | | 3444 | | |
| | | 3445 | | SUCCESS: |
| | | 3446 | | if (!self.TrySetResult()) |
| | | 3447 | | { |
| | | 3448 | | if (self.syncRunning) return; |
| | | 3449 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 3450 | | try |
| | | 3451 | | { |
| | | 3452 | | self.awaiter4 = self.enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 3453 | | } |
| | | 3454 | | catch (Exception ex) |
| | | 3455 | | { |
| | | 3456 | | self.completedCount = CompleteCount; |
| | | 3457 | | self.completionSource.TrySetException(ex); |
| | | 3458 | | return; |
| | | 3459 | | } |
| | | 3460 | | |
| | | 3461 | | self.awaiter4.SourceOnCompleted(Completed4Delegate, self); |
| | | 3462 | | } |
| | | 3463 | | return; |
| | | 3464 | | COMPLETE: |
| | | 3465 | | self.completionSource.TrySetResult(false); |
| | | 3466 | | return; |
| | | 3467 | | } |
| | | 3468 | | |
| | | 3469 | | static void Completed5(object state) |
| | | 3470 | | { |
| | | 3471 | | var self = (_CombineLatest)state; |
| | | 3472 | | self.running5 = false; |
| | | 3473 | | |
| | | 3474 | | try |
| | | 3475 | | { |
| | | 3476 | | if (self.awaiter5.GetResult()) |
| | | 3477 | | { |
| | | 3478 | | self.hasCurrent5 = true; |
| | | 3479 | | self.current5 = self.enumerator5.Current; |
| | | 3480 | | goto SUCCESS; |
| | | 3481 | | } |
| | | 3482 | | else |
| | | 3483 | | { |
| | | 3484 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 3485 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 3486 | | { |
| | | 3487 | | goto COMPLETE; |
| | | 3488 | | } |
| | | 3489 | | return; |
| | | 3490 | | } |
| | | 3491 | | } |
| | | 3492 | | catch (Exception ex) |
| | | 3493 | | { |
| | | 3494 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 3495 | | self.completedCount = CompleteCount; |
| | | 3496 | | self.completionSource.TrySetException(ex); |
| | | 3497 | | return; |
| | | 3498 | | } |
| | | 3499 | | |
| | | 3500 | | SUCCESS: |
| | | 3501 | | if (!self.TrySetResult()) |
| | | 3502 | | { |
| | | 3503 | | if (self.syncRunning) return; |
| | | 3504 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 3505 | | try |
| | | 3506 | | { |
| | | 3507 | | self.awaiter5 = self.enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 3508 | | } |
| | | 3509 | | catch (Exception ex) |
| | | 3510 | | { |
| | | 3511 | | self.completedCount = CompleteCount; |
| | | 3512 | | self.completionSource.TrySetException(ex); |
| | | 3513 | | return; |
| | | 3514 | | } |
| | | 3515 | | |
| | | 3516 | | self.awaiter5.SourceOnCompleted(Completed5Delegate, self); |
| | | 3517 | | } |
| | | 3518 | | return; |
| | | 3519 | | COMPLETE: |
| | | 3520 | | self.completionSource.TrySetResult(false); |
| | | 3521 | | return; |
| | | 3522 | | } |
| | | 3523 | | |
| | | 3524 | | static void Completed6(object state) |
| | | 3525 | | { |
| | | 3526 | | var self = (_CombineLatest)state; |
| | | 3527 | | self.running6 = false; |
| | | 3528 | | |
| | | 3529 | | try |
| | | 3530 | | { |
| | | 3531 | | if (self.awaiter6.GetResult()) |
| | | 3532 | | { |
| | | 3533 | | self.hasCurrent6 = true; |
| | | 3534 | | self.current6 = self.enumerator6.Current; |
| | | 3535 | | goto SUCCESS; |
| | | 3536 | | } |
| | | 3537 | | else |
| | | 3538 | | { |
| | | 3539 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 3540 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 3541 | | { |
| | | 3542 | | goto COMPLETE; |
| | | 3543 | | } |
| | | 3544 | | return; |
| | | 3545 | | } |
| | | 3546 | | } |
| | | 3547 | | catch (Exception ex) |
| | | 3548 | | { |
| | | 3549 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 3550 | | self.completedCount = CompleteCount; |
| | | 3551 | | self.completionSource.TrySetException(ex); |
| | | 3552 | | return; |
| | | 3553 | | } |
| | | 3554 | | |
| | | 3555 | | SUCCESS: |
| | | 3556 | | if (!self.TrySetResult()) |
| | | 3557 | | { |
| | | 3558 | | if (self.syncRunning) return; |
| | | 3559 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 3560 | | try |
| | | 3561 | | { |
| | | 3562 | | self.awaiter6 = self.enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 3563 | | } |
| | | 3564 | | catch (Exception ex) |
| | | 3565 | | { |
| | | 3566 | | self.completedCount = CompleteCount; |
| | | 3567 | | self.completionSource.TrySetException(ex); |
| | | 3568 | | return; |
| | | 3569 | | } |
| | | 3570 | | |
| | | 3571 | | self.awaiter6.SourceOnCompleted(Completed6Delegate, self); |
| | | 3572 | | } |
| | | 3573 | | return; |
| | | 3574 | | COMPLETE: |
| | | 3575 | | self.completionSource.TrySetResult(false); |
| | | 3576 | | return; |
| | | 3577 | | } |
| | | 3578 | | |
| | | 3579 | | static void Completed7(object state) |
| | | 3580 | | { |
| | | 3581 | | var self = (_CombineLatest)state; |
| | | 3582 | | self.running7 = false; |
| | | 3583 | | |
| | | 3584 | | try |
| | | 3585 | | { |
| | | 3586 | | if (self.awaiter7.GetResult()) |
| | | 3587 | | { |
| | | 3588 | | self.hasCurrent7 = true; |
| | | 3589 | | self.current7 = self.enumerator7.Current; |
| | | 3590 | | goto SUCCESS; |
| | | 3591 | | } |
| | | 3592 | | else |
| | | 3593 | | { |
| | | 3594 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 3595 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 3596 | | { |
| | | 3597 | | goto COMPLETE; |
| | | 3598 | | } |
| | | 3599 | | return; |
| | | 3600 | | } |
| | | 3601 | | } |
| | | 3602 | | catch (Exception ex) |
| | | 3603 | | { |
| | | 3604 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 3605 | | self.completedCount = CompleteCount; |
| | | 3606 | | self.completionSource.TrySetException(ex); |
| | | 3607 | | return; |
| | | 3608 | | } |
| | | 3609 | | |
| | | 3610 | | SUCCESS: |
| | | 3611 | | if (!self.TrySetResult()) |
| | | 3612 | | { |
| | | 3613 | | if (self.syncRunning) return; |
| | | 3614 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 3615 | | try |
| | | 3616 | | { |
| | | 3617 | | self.awaiter7 = self.enumerator7.MoveNextAsync().GetAwaiter(); |
| | | 3618 | | } |
| | | 3619 | | catch (Exception ex) |
| | | 3620 | | { |
| | | 3621 | | self.completedCount = CompleteCount; |
| | | 3622 | | self.completionSource.TrySetException(ex); |
| | | 3623 | | return; |
| | | 3624 | | } |
| | | 3625 | | |
| | | 3626 | | self.awaiter7.SourceOnCompleted(Completed7Delegate, self); |
| | | 3627 | | } |
| | | 3628 | | return; |
| | | 3629 | | COMPLETE: |
| | | 3630 | | self.completionSource.TrySetResult(false); |
| | | 3631 | | return; |
| | | 3632 | | } |
| | | 3633 | | |
| | | 3634 | | static void Completed8(object state) |
| | | 3635 | | { |
| | | 3636 | | var self = (_CombineLatest)state; |
| | | 3637 | | self.running8 = false; |
| | | 3638 | | |
| | | 3639 | | try |
| | | 3640 | | { |
| | | 3641 | | if (self.awaiter8.GetResult()) |
| | | 3642 | | { |
| | | 3643 | | self.hasCurrent8 = true; |
| | | 3644 | | self.current8 = self.enumerator8.Current; |
| | | 3645 | | goto SUCCESS; |
| | | 3646 | | } |
| | | 3647 | | else |
| | | 3648 | | { |
| | | 3649 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 3650 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 3651 | | { |
| | | 3652 | | goto COMPLETE; |
| | | 3653 | | } |
| | | 3654 | | return; |
| | | 3655 | | } |
| | | 3656 | | } |
| | | 3657 | | catch (Exception ex) |
| | | 3658 | | { |
| | | 3659 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 3660 | | self.completedCount = CompleteCount; |
| | | 3661 | | self.completionSource.TrySetException(ex); |
| | | 3662 | | return; |
| | | 3663 | | } |
| | | 3664 | | |
| | | 3665 | | SUCCESS: |
| | | 3666 | | if (!self.TrySetResult()) |
| | | 3667 | | { |
| | | 3668 | | if (self.syncRunning) return; |
| | | 3669 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 3670 | | try |
| | | 3671 | | { |
| | | 3672 | | self.awaiter8 = self.enumerator8.MoveNextAsync().GetAwaiter(); |
| | | 3673 | | } |
| | | 3674 | | catch (Exception ex) |
| | | 3675 | | { |
| | | 3676 | | self.completedCount = CompleteCount; |
| | | 3677 | | self.completionSource.TrySetException(ex); |
| | | 3678 | | return; |
| | | 3679 | | } |
| | | 3680 | | |
| | | 3681 | | self.awaiter8.SourceOnCompleted(Completed8Delegate, self); |
| | | 3682 | | } |
| | | 3683 | | return; |
| | | 3684 | | COMPLETE: |
| | | 3685 | | self.completionSource.TrySetResult(false); |
| | | 3686 | | return; |
| | | 3687 | | } |
| | | 3688 | | |
| | | 3689 | | bool TrySetResult() |
| | | 3690 | | { |
| | | 3691 | | if (hasCurrent1 && hasCurrent2 && hasCurrent3 && hasCurrent4 && hasCurrent5 && hasCurrent6 && hasCurrent |
| | | 3692 | | { |
| | | 3693 | | result = resultSelector(current1, current2, current3, current4, current5, current6, current7, curren |
| | | 3694 | | completionSource.TrySetResult(true); |
| | | 3695 | | return true; |
| | | 3696 | | } |
| | | 3697 | | else |
| | | 3698 | | { |
| | | 3699 | | return false; |
| | | 3700 | | } |
| | | 3701 | | } |
| | | 3702 | | |
| | | 3703 | | public async UniTask DisposeAsync() |
| | | 3704 | | { |
| | | 3705 | | TaskTracker.RemoveTracking(this); |
| | | 3706 | | if (enumerator1 != null) |
| | | 3707 | | { |
| | | 3708 | | await enumerator1.DisposeAsync(); |
| | | 3709 | | } |
| | | 3710 | | if (enumerator2 != null) |
| | | 3711 | | { |
| | | 3712 | | await enumerator2.DisposeAsync(); |
| | | 3713 | | } |
| | | 3714 | | if (enumerator3 != null) |
| | | 3715 | | { |
| | | 3716 | | await enumerator3.DisposeAsync(); |
| | | 3717 | | } |
| | | 3718 | | if (enumerator4 != null) |
| | | 3719 | | { |
| | | 3720 | | await enumerator4.DisposeAsync(); |
| | | 3721 | | } |
| | | 3722 | | if (enumerator5 != null) |
| | | 3723 | | { |
| | | 3724 | | await enumerator5.DisposeAsync(); |
| | | 3725 | | } |
| | | 3726 | | if (enumerator6 != null) |
| | | 3727 | | { |
| | | 3728 | | await enumerator6.DisposeAsync(); |
| | | 3729 | | } |
| | | 3730 | | if (enumerator7 != null) |
| | | 3731 | | { |
| | | 3732 | | await enumerator7.DisposeAsync(); |
| | | 3733 | | } |
| | | 3734 | | if (enumerator8 != null) |
| | | 3735 | | { |
| | | 3736 | | await enumerator8.DisposeAsync(); |
| | | 3737 | | } |
| | | 3738 | | } |
| | | 3739 | | } |
| | | 3740 | | } |
| | | 3741 | | |
| | | 3742 | | internal class CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> : IUniTaskAsyncEnumerable<TResult> |
| | | 3743 | | { |
| | | 3744 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 3745 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 3746 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 3747 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 3748 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 3749 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 3750 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 3751 | | readonly IUniTaskAsyncEnumerable<T8> source8; |
| | | 3752 | | readonly IUniTaskAsyncEnumerable<T9> source9; |
| | | 3753 | | |
| | | 3754 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> resultSelector; |
| | | 3755 | | |
| | | 3756 | | public CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyncEnum |
| | | 3757 | | { |
| | | 3758 | | this.source1 = source1; |
| | | 3759 | | this.source2 = source2; |
| | | 3760 | | this.source3 = source3; |
| | | 3761 | | this.source4 = source4; |
| | | 3762 | | this.source5 = source5; |
| | | 3763 | | this.source6 = source6; |
| | | 3764 | | this.source7 = source7; |
| | | 3765 | | this.source8 = source8; |
| | | 3766 | | this.source9 = source9; |
| | | 3767 | | |
| | | 3768 | | this.resultSelector = resultSelector; |
| | | 3769 | | } |
| | | 3770 | | |
| | | 3771 | | public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default) |
| | | 3772 | | { |
| | | 3773 | | return new _CombineLatest(source1, source2, source3, source4, source5, source6, source7, source8, source9, r |
| | | 3774 | | } |
| | | 3775 | | |
| | | 3776 | | class _CombineLatest : MoveNextSource, IUniTaskAsyncEnumerator<TResult> |
| | | 3777 | | { |
| | | 3778 | | static readonly Action<object> Completed1Delegate = Completed1; |
| | | 3779 | | static readonly Action<object> Completed2Delegate = Completed2; |
| | | 3780 | | static readonly Action<object> Completed3Delegate = Completed3; |
| | | 3781 | | static readonly Action<object> Completed4Delegate = Completed4; |
| | | 3782 | | static readonly Action<object> Completed5Delegate = Completed5; |
| | | 3783 | | static readonly Action<object> Completed6Delegate = Completed6; |
| | | 3784 | | static readonly Action<object> Completed7Delegate = Completed7; |
| | | 3785 | | static readonly Action<object> Completed8Delegate = Completed8; |
| | | 3786 | | static readonly Action<object> Completed9Delegate = Completed9; |
| | | 3787 | | const int CompleteCount = 9; |
| | | 3788 | | |
| | | 3789 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 3790 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 3791 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 3792 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 3793 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 3794 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 3795 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 3796 | | readonly IUniTaskAsyncEnumerable<T8> source8; |
| | | 3797 | | readonly IUniTaskAsyncEnumerable<T9> source9; |
| | | 3798 | | |
| | | 3799 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> resultSelector; |
| | | 3800 | | CancellationToken cancellationToken; |
| | | 3801 | | |
| | | 3802 | | IUniTaskAsyncEnumerator<T1> enumerator1; |
| | | 3803 | | UniTask<bool>.Awaiter awaiter1; |
| | | 3804 | | bool hasCurrent1; |
| | | 3805 | | bool running1; |
| | | 3806 | | T1 current1; |
| | | 3807 | | |
| | | 3808 | | IUniTaskAsyncEnumerator<T2> enumerator2; |
| | | 3809 | | UniTask<bool>.Awaiter awaiter2; |
| | | 3810 | | bool hasCurrent2; |
| | | 3811 | | bool running2; |
| | | 3812 | | T2 current2; |
| | | 3813 | | |
| | | 3814 | | IUniTaskAsyncEnumerator<T3> enumerator3; |
| | | 3815 | | UniTask<bool>.Awaiter awaiter3; |
| | | 3816 | | bool hasCurrent3; |
| | | 3817 | | bool running3; |
| | | 3818 | | T3 current3; |
| | | 3819 | | |
| | | 3820 | | IUniTaskAsyncEnumerator<T4> enumerator4; |
| | | 3821 | | UniTask<bool>.Awaiter awaiter4; |
| | | 3822 | | bool hasCurrent4; |
| | | 3823 | | bool running4; |
| | | 3824 | | T4 current4; |
| | | 3825 | | |
| | | 3826 | | IUniTaskAsyncEnumerator<T5> enumerator5; |
| | | 3827 | | UniTask<bool>.Awaiter awaiter5; |
| | | 3828 | | bool hasCurrent5; |
| | | 3829 | | bool running5; |
| | | 3830 | | T5 current5; |
| | | 3831 | | |
| | | 3832 | | IUniTaskAsyncEnumerator<T6> enumerator6; |
| | | 3833 | | UniTask<bool>.Awaiter awaiter6; |
| | | 3834 | | bool hasCurrent6; |
| | | 3835 | | bool running6; |
| | | 3836 | | T6 current6; |
| | | 3837 | | |
| | | 3838 | | IUniTaskAsyncEnumerator<T7> enumerator7; |
| | | 3839 | | UniTask<bool>.Awaiter awaiter7; |
| | | 3840 | | bool hasCurrent7; |
| | | 3841 | | bool running7; |
| | | 3842 | | T7 current7; |
| | | 3843 | | |
| | | 3844 | | IUniTaskAsyncEnumerator<T8> enumerator8; |
| | | 3845 | | UniTask<bool>.Awaiter awaiter8; |
| | | 3846 | | bool hasCurrent8; |
| | | 3847 | | bool running8; |
| | | 3848 | | T8 current8; |
| | | 3849 | | |
| | | 3850 | | IUniTaskAsyncEnumerator<T9> enumerator9; |
| | | 3851 | | UniTask<bool>.Awaiter awaiter9; |
| | | 3852 | | bool hasCurrent9; |
| | | 3853 | | bool running9; |
| | | 3854 | | T9 current9; |
| | | 3855 | | |
| | | 3856 | | int completedCount; |
| | | 3857 | | bool syncRunning; |
| | | 3858 | | TResult result; |
| | | 3859 | | |
| | | 3860 | | public _CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyn |
| | | 3861 | | { |
| | | 3862 | | this.source1 = source1; |
| | | 3863 | | this.source2 = source2; |
| | | 3864 | | this.source3 = source3; |
| | | 3865 | | this.source4 = source4; |
| | | 3866 | | this.source5 = source5; |
| | | 3867 | | this.source6 = source6; |
| | | 3868 | | this.source7 = source7; |
| | | 3869 | | this.source8 = source8; |
| | | 3870 | | this.source9 = source9; |
| | | 3871 | | |
| | | 3872 | | this.resultSelector = resultSelector; |
| | | 3873 | | this.cancellationToken = cancellationToken; |
| | | 3874 | | TaskTracker.TrackActiveTask(this, 3); |
| | | 3875 | | } |
| | | 3876 | | |
| | | 3877 | | public TResult Current => result; |
| | | 3878 | | |
| | | 3879 | | public UniTask<bool> MoveNextAsync() |
| | | 3880 | | { |
| | | 3881 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 3882 | | if (completedCount == CompleteCount) return CompletedTasks.False; |
| | | 3883 | | |
| | | 3884 | | if (enumerator1 == null) |
| | | 3885 | | { |
| | | 3886 | | enumerator1 = source1.GetAsyncEnumerator(cancellationToken); |
| | | 3887 | | enumerator2 = source2.GetAsyncEnumerator(cancellationToken); |
| | | 3888 | | enumerator3 = source3.GetAsyncEnumerator(cancellationToken); |
| | | 3889 | | enumerator4 = source4.GetAsyncEnumerator(cancellationToken); |
| | | 3890 | | enumerator5 = source5.GetAsyncEnumerator(cancellationToken); |
| | | 3891 | | enumerator6 = source6.GetAsyncEnumerator(cancellationToken); |
| | | 3892 | | enumerator7 = source7.GetAsyncEnumerator(cancellationToken); |
| | | 3893 | | enumerator8 = source8.GetAsyncEnumerator(cancellationToken); |
| | | 3894 | | enumerator9 = source9.GetAsyncEnumerator(cancellationToken); |
| | | 3895 | | } |
| | | 3896 | | |
| | | 3897 | | completionSource.Reset(); |
| | | 3898 | | |
| | | 3899 | | AGAIN: |
| | | 3900 | | syncRunning = true; |
| | | 3901 | | if (!running1) |
| | | 3902 | | { |
| | | 3903 | | running1 = true; |
| | | 3904 | | awaiter1 = enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 3905 | | if (awaiter1.IsCompleted) |
| | | 3906 | | { |
| | | 3907 | | Completed1(this); |
| | | 3908 | | } |
| | | 3909 | | else |
| | | 3910 | | { |
| | | 3911 | | awaiter1.SourceOnCompleted(Completed1Delegate, this); |
| | | 3912 | | } |
| | | 3913 | | } |
| | | 3914 | | if (!running2) |
| | | 3915 | | { |
| | | 3916 | | running2 = true; |
| | | 3917 | | awaiter2 = enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 3918 | | if (awaiter2.IsCompleted) |
| | | 3919 | | { |
| | | 3920 | | Completed2(this); |
| | | 3921 | | } |
| | | 3922 | | else |
| | | 3923 | | { |
| | | 3924 | | awaiter2.SourceOnCompleted(Completed2Delegate, this); |
| | | 3925 | | } |
| | | 3926 | | } |
| | | 3927 | | if (!running3) |
| | | 3928 | | { |
| | | 3929 | | running3 = true; |
| | | 3930 | | awaiter3 = enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 3931 | | if (awaiter3.IsCompleted) |
| | | 3932 | | { |
| | | 3933 | | Completed3(this); |
| | | 3934 | | } |
| | | 3935 | | else |
| | | 3936 | | { |
| | | 3937 | | awaiter3.SourceOnCompleted(Completed3Delegate, this); |
| | | 3938 | | } |
| | | 3939 | | } |
| | | 3940 | | if (!running4) |
| | | 3941 | | { |
| | | 3942 | | running4 = true; |
| | | 3943 | | awaiter4 = enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 3944 | | if (awaiter4.IsCompleted) |
| | | 3945 | | { |
| | | 3946 | | Completed4(this); |
| | | 3947 | | } |
| | | 3948 | | else |
| | | 3949 | | { |
| | | 3950 | | awaiter4.SourceOnCompleted(Completed4Delegate, this); |
| | | 3951 | | } |
| | | 3952 | | } |
| | | 3953 | | if (!running5) |
| | | 3954 | | { |
| | | 3955 | | running5 = true; |
| | | 3956 | | awaiter5 = enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 3957 | | if (awaiter5.IsCompleted) |
| | | 3958 | | { |
| | | 3959 | | Completed5(this); |
| | | 3960 | | } |
| | | 3961 | | else |
| | | 3962 | | { |
| | | 3963 | | awaiter5.SourceOnCompleted(Completed5Delegate, this); |
| | | 3964 | | } |
| | | 3965 | | } |
| | | 3966 | | if (!running6) |
| | | 3967 | | { |
| | | 3968 | | running6 = true; |
| | | 3969 | | awaiter6 = enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 3970 | | if (awaiter6.IsCompleted) |
| | | 3971 | | { |
| | | 3972 | | Completed6(this); |
| | | 3973 | | } |
| | | 3974 | | else |
| | | 3975 | | { |
| | | 3976 | | awaiter6.SourceOnCompleted(Completed6Delegate, this); |
| | | 3977 | | } |
| | | 3978 | | } |
| | | 3979 | | if (!running7) |
| | | 3980 | | { |
| | | 3981 | | running7 = true; |
| | | 3982 | | awaiter7 = enumerator7.MoveNextAsync().GetAwaiter(); |
| | | 3983 | | if (awaiter7.IsCompleted) |
| | | 3984 | | { |
| | | 3985 | | Completed7(this); |
| | | 3986 | | } |
| | | 3987 | | else |
| | | 3988 | | { |
| | | 3989 | | awaiter7.SourceOnCompleted(Completed7Delegate, this); |
| | | 3990 | | } |
| | | 3991 | | } |
| | | 3992 | | if (!running8) |
| | | 3993 | | { |
| | | 3994 | | running8 = true; |
| | | 3995 | | awaiter8 = enumerator8.MoveNextAsync().GetAwaiter(); |
| | | 3996 | | if (awaiter8.IsCompleted) |
| | | 3997 | | { |
| | | 3998 | | Completed8(this); |
| | | 3999 | | } |
| | | 4000 | | else |
| | | 4001 | | { |
| | | 4002 | | awaiter8.SourceOnCompleted(Completed8Delegate, this); |
| | | 4003 | | } |
| | | 4004 | | } |
| | | 4005 | | if (!running9) |
| | | 4006 | | { |
| | | 4007 | | running9 = true; |
| | | 4008 | | awaiter9 = enumerator9.MoveNextAsync().GetAwaiter(); |
| | | 4009 | | if (awaiter9.IsCompleted) |
| | | 4010 | | { |
| | | 4011 | | Completed9(this); |
| | | 4012 | | } |
| | | 4013 | | else |
| | | 4014 | | { |
| | | 4015 | | awaiter9.SourceOnCompleted(Completed9Delegate, this); |
| | | 4016 | | } |
| | | 4017 | | } |
| | | 4018 | | |
| | | 4019 | | if (!running1 || !running2 || !running3 || !running4 || !running5 || !running6 || !running7 || !running8 |
| | | 4020 | | { |
| | | 4021 | | goto AGAIN; |
| | | 4022 | | } |
| | | 4023 | | syncRunning = false; |
| | | 4024 | | |
| | | 4025 | | return new UniTask<bool>(this, completionSource.Version); |
| | | 4026 | | } |
| | | 4027 | | |
| | | 4028 | | static void Completed1(object state) |
| | | 4029 | | { |
| | | 4030 | | var self = (_CombineLatest)state; |
| | | 4031 | | self.running1 = false; |
| | | 4032 | | |
| | | 4033 | | try |
| | | 4034 | | { |
| | | 4035 | | if (self.awaiter1.GetResult()) |
| | | 4036 | | { |
| | | 4037 | | self.hasCurrent1 = true; |
| | | 4038 | | self.current1 = self.enumerator1.Current; |
| | | 4039 | | goto SUCCESS; |
| | | 4040 | | } |
| | | 4041 | | else |
| | | 4042 | | { |
| | | 4043 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 4044 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 4045 | | { |
| | | 4046 | | goto COMPLETE; |
| | | 4047 | | } |
| | | 4048 | | return; |
| | | 4049 | | } |
| | | 4050 | | } |
| | | 4051 | | catch (Exception ex) |
| | | 4052 | | { |
| | | 4053 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 4054 | | self.completedCount = CompleteCount; |
| | | 4055 | | self.completionSource.TrySetException(ex); |
| | | 4056 | | return; |
| | | 4057 | | } |
| | | 4058 | | |
| | | 4059 | | SUCCESS: |
| | | 4060 | | if (!self.TrySetResult()) |
| | | 4061 | | { |
| | | 4062 | | if (self.syncRunning) return; |
| | | 4063 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 4064 | | try |
| | | 4065 | | { |
| | | 4066 | | self.awaiter1 = self.enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 4067 | | } |
| | | 4068 | | catch (Exception ex) |
| | | 4069 | | { |
| | | 4070 | | self.completedCount = CompleteCount; |
| | | 4071 | | self.completionSource.TrySetException(ex); |
| | | 4072 | | return; |
| | | 4073 | | } |
| | | 4074 | | |
| | | 4075 | | self.awaiter1.SourceOnCompleted(Completed1Delegate, self); |
| | | 4076 | | } |
| | | 4077 | | return; |
| | | 4078 | | COMPLETE: |
| | | 4079 | | self.completionSource.TrySetResult(false); |
| | | 4080 | | return; |
| | | 4081 | | } |
| | | 4082 | | |
| | | 4083 | | static void Completed2(object state) |
| | | 4084 | | { |
| | | 4085 | | var self = (_CombineLatest)state; |
| | | 4086 | | self.running2 = false; |
| | | 4087 | | |
| | | 4088 | | try |
| | | 4089 | | { |
| | | 4090 | | if (self.awaiter2.GetResult()) |
| | | 4091 | | { |
| | | 4092 | | self.hasCurrent2 = true; |
| | | 4093 | | self.current2 = self.enumerator2.Current; |
| | | 4094 | | goto SUCCESS; |
| | | 4095 | | } |
| | | 4096 | | else |
| | | 4097 | | { |
| | | 4098 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 4099 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 4100 | | { |
| | | 4101 | | goto COMPLETE; |
| | | 4102 | | } |
| | | 4103 | | return; |
| | | 4104 | | } |
| | | 4105 | | } |
| | | 4106 | | catch (Exception ex) |
| | | 4107 | | { |
| | | 4108 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 4109 | | self.completedCount = CompleteCount; |
| | | 4110 | | self.completionSource.TrySetException(ex); |
| | | 4111 | | return; |
| | | 4112 | | } |
| | | 4113 | | |
| | | 4114 | | SUCCESS: |
| | | 4115 | | if (!self.TrySetResult()) |
| | | 4116 | | { |
| | | 4117 | | if (self.syncRunning) return; |
| | | 4118 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 4119 | | try |
| | | 4120 | | { |
| | | 4121 | | self.awaiter2 = self.enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 4122 | | } |
| | | 4123 | | catch (Exception ex) |
| | | 4124 | | { |
| | | 4125 | | self.completedCount = CompleteCount; |
| | | 4126 | | self.completionSource.TrySetException(ex); |
| | | 4127 | | return; |
| | | 4128 | | } |
| | | 4129 | | |
| | | 4130 | | self.awaiter2.SourceOnCompleted(Completed2Delegate, self); |
| | | 4131 | | } |
| | | 4132 | | return; |
| | | 4133 | | COMPLETE: |
| | | 4134 | | self.completionSource.TrySetResult(false); |
| | | 4135 | | return; |
| | | 4136 | | } |
| | | 4137 | | |
| | | 4138 | | static void Completed3(object state) |
| | | 4139 | | { |
| | | 4140 | | var self = (_CombineLatest)state; |
| | | 4141 | | self.running3 = false; |
| | | 4142 | | |
| | | 4143 | | try |
| | | 4144 | | { |
| | | 4145 | | if (self.awaiter3.GetResult()) |
| | | 4146 | | { |
| | | 4147 | | self.hasCurrent3 = true; |
| | | 4148 | | self.current3 = self.enumerator3.Current; |
| | | 4149 | | goto SUCCESS; |
| | | 4150 | | } |
| | | 4151 | | else |
| | | 4152 | | { |
| | | 4153 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 4154 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 4155 | | { |
| | | 4156 | | goto COMPLETE; |
| | | 4157 | | } |
| | | 4158 | | return; |
| | | 4159 | | } |
| | | 4160 | | } |
| | | 4161 | | catch (Exception ex) |
| | | 4162 | | { |
| | | 4163 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 4164 | | self.completedCount = CompleteCount; |
| | | 4165 | | self.completionSource.TrySetException(ex); |
| | | 4166 | | return; |
| | | 4167 | | } |
| | | 4168 | | |
| | | 4169 | | SUCCESS: |
| | | 4170 | | if (!self.TrySetResult()) |
| | | 4171 | | { |
| | | 4172 | | if (self.syncRunning) return; |
| | | 4173 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 4174 | | try |
| | | 4175 | | { |
| | | 4176 | | self.awaiter3 = self.enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 4177 | | } |
| | | 4178 | | catch (Exception ex) |
| | | 4179 | | { |
| | | 4180 | | self.completedCount = CompleteCount; |
| | | 4181 | | self.completionSource.TrySetException(ex); |
| | | 4182 | | return; |
| | | 4183 | | } |
| | | 4184 | | |
| | | 4185 | | self.awaiter3.SourceOnCompleted(Completed3Delegate, self); |
| | | 4186 | | } |
| | | 4187 | | return; |
| | | 4188 | | COMPLETE: |
| | | 4189 | | self.completionSource.TrySetResult(false); |
| | | 4190 | | return; |
| | | 4191 | | } |
| | | 4192 | | |
| | | 4193 | | static void Completed4(object state) |
| | | 4194 | | { |
| | | 4195 | | var self = (_CombineLatest)state; |
| | | 4196 | | self.running4 = false; |
| | | 4197 | | |
| | | 4198 | | try |
| | | 4199 | | { |
| | | 4200 | | if (self.awaiter4.GetResult()) |
| | | 4201 | | { |
| | | 4202 | | self.hasCurrent4 = true; |
| | | 4203 | | self.current4 = self.enumerator4.Current; |
| | | 4204 | | goto SUCCESS; |
| | | 4205 | | } |
| | | 4206 | | else |
| | | 4207 | | { |
| | | 4208 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 4209 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 4210 | | { |
| | | 4211 | | goto COMPLETE; |
| | | 4212 | | } |
| | | 4213 | | return; |
| | | 4214 | | } |
| | | 4215 | | } |
| | | 4216 | | catch (Exception ex) |
| | | 4217 | | { |
| | | 4218 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 4219 | | self.completedCount = CompleteCount; |
| | | 4220 | | self.completionSource.TrySetException(ex); |
| | | 4221 | | return; |
| | | 4222 | | } |
| | | 4223 | | |
| | | 4224 | | SUCCESS: |
| | | 4225 | | if (!self.TrySetResult()) |
| | | 4226 | | { |
| | | 4227 | | if (self.syncRunning) return; |
| | | 4228 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 4229 | | try |
| | | 4230 | | { |
| | | 4231 | | self.awaiter4 = self.enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 4232 | | } |
| | | 4233 | | catch (Exception ex) |
| | | 4234 | | { |
| | | 4235 | | self.completedCount = CompleteCount; |
| | | 4236 | | self.completionSource.TrySetException(ex); |
| | | 4237 | | return; |
| | | 4238 | | } |
| | | 4239 | | |
| | | 4240 | | self.awaiter4.SourceOnCompleted(Completed4Delegate, self); |
| | | 4241 | | } |
| | | 4242 | | return; |
| | | 4243 | | COMPLETE: |
| | | 4244 | | self.completionSource.TrySetResult(false); |
| | | 4245 | | return; |
| | | 4246 | | } |
| | | 4247 | | |
| | | 4248 | | static void Completed5(object state) |
| | | 4249 | | { |
| | | 4250 | | var self = (_CombineLatest)state; |
| | | 4251 | | self.running5 = false; |
| | | 4252 | | |
| | | 4253 | | try |
| | | 4254 | | { |
| | | 4255 | | if (self.awaiter5.GetResult()) |
| | | 4256 | | { |
| | | 4257 | | self.hasCurrent5 = true; |
| | | 4258 | | self.current5 = self.enumerator5.Current; |
| | | 4259 | | goto SUCCESS; |
| | | 4260 | | } |
| | | 4261 | | else |
| | | 4262 | | { |
| | | 4263 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 4264 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 4265 | | { |
| | | 4266 | | goto COMPLETE; |
| | | 4267 | | } |
| | | 4268 | | return; |
| | | 4269 | | } |
| | | 4270 | | } |
| | | 4271 | | catch (Exception ex) |
| | | 4272 | | { |
| | | 4273 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 4274 | | self.completedCount = CompleteCount; |
| | | 4275 | | self.completionSource.TrySetException(ex); |
| | | 4276 | | return; |
| | | 4277 | | } |
| | | 4278 | | |
| | | 4279 | | SUCCESS: |
| | | 4280 | | if (!self.TrySetResult()) |
| | | 4281 | | { |
| | | 4282 | | if (self.syncRunning) return; |
| | | 4283 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 4284 | | try |
| | | 4285 | | { |
| | | 4286 | | self.awaiter5 = self.enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 4287 | | } |
| | | 4288 | | catch (Exception ex) |
| | | 4289 | | { |
| | | 4290 | | self.completedCount = CompleteCount; |
| | | 4291 | | self.completionSource.TrySetException(ex); |
| | | 4292 | | return; |
| | | 4293 | | } |
| | | 4294 | | |
| | | 4295 | | self.awaiter5.SourceOnCompleted(Completed5Delegate, self); |
| | | 4296 | | } |
| | | 4297 | | return; |
| | | 4298 | | COMPLETE: |
| | | 4299 | | self.completionSource.TrySetResult(false); |
| | | 4300 | | return; |
| | | 4301 | | } |
| | | 4302 | | |
| | | 4303 | | static void Completed6(object state) |
| | | 4304 | | { |
| | | 4305 | | var self = (_CombineLatest)state; |
| | | 4306 | | self.running6 = false; |
| | | 4307 | | |
| | | 4308 | | try |
| | | 4309 | | { |
| | | 4310 | | if (self.awaiter6.GetResult()) |
| | | 4311 | | { |
| | | 4312 | | self.hasCurrent6 = true; |
| | | 4313 | | self.current6 = self.enumerator6.Current; |
| | | 4314 | | goto SUCCESS; |
| | | 4315 | | } |
| | | 4316 | | else |
| | | 4317 | | { |
| | | 4318 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 4319 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 4320 | | { |
| | | 4321 | | goto COMPLETE; |
| | | 4322 | | } |
| | | 4323 | | return; |
| | | 4324 | | } |
| | | 4325 | | } |
| | | 4326 | | catch (Exception ex) |
| | | 4327 | | { |
| | | 4328 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 4329 | | self.completedCount = CompleteCount; |
| | | 4330 | | self.completionSource.TrySetException(ex); |
| | | 4331 | | return; |
| | | 4332 | | } |
| | | 4333 | | |
| | | 4334 | | SUCCESS: |
| | | 4335 | | if (!self.TrySetResult()) |
| | | 4336 | | { |
| | | 4337 | | if (self.syncRunning) return; |
| | | 4338 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 4339 | | try |
| | | 4340 | | { |
| | | 4341 | | self.awaiter6 = self.enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 4342 | | } |
| | | 4343 | | catch (Exception ex) |
| | | 4344 | | { |
| | | 4345 | | self.completedCount = CompleteCount; |
| | | 4346 | | self.completionSource.TrySetException(ex); |
| | | 4347 | | return; |
| | | 4348 | | } |
| | | 4349 | | |
| | | 4350 | | self.awaiter6.SourceOnCompleted(Completed6Delegate, self); |
| | | 4351 | | } |
| | | 4352 | | return; |
| | | 4353 | | COMPLETE: |
| | | 4354 | | self.completionSource.TrySetResult(false); |
| | | 4355 | | return; |
| | | 4356 | | } |
| | | 4357 | | |
| | | 4358 | | static void Completed7(object state) |
| | | 4359 | | { |
| | | 4360 | | var self = (_CombineLatest)state; |
| | | 4361 | | self.running7 = false; |
| | | 4362 | | |
| | | 4363 | | try |
| | | 4364 | | { |
| | | 4365 | | if (self.awaiter7.GetResult()) |
| | | 4366 | | { |
| | | 4367 | | self.hasCurrent7 = true; |
| | | 4368 | | self.current7 = self.enumerator7.Current; |
| | | 4369 | | goto SUCCESS; |
| | | 4370 | | } |
| | | 4371 | | else |
| | | 4372 | | { |
| | | 4373 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 4374 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 4375 | | { |
| | | 4376 | | goto COMPLETE; |
| | | 4377 | | } |
| | | 4378 | | return; |
| | | 4379 | | } |
| | | 4380 | | } |
| | | 4381 | | catch (Exception ex) |
| | | 4382 | | { |
| | | 4383 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 4384 | | self.completedCount = CompleteCount; |
| | | 4385 | | self.completionSource.TrySetException(ex); |
| | | 4386 | | return; |
| | | 4387 | | } |
| | | 4388 | | |
| | | 4389 | | SUCCESS: |
| | | 4390 | | if (!self.TrySetResult()) |
| | | 4391 | | { |
| | | 4392 | | if (self.syncRunning) return; |
| | | 4393 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 4394 | | try |
| | | 4395 | | { |
| | | 4396 | | self.awaiter7 = self.enumerator7.MoveNextAsync().GetAwaiter(); |
| | | 4397 | | } |
| | | 4398 | | catch (Exception ex) |
| | | 4399 | | { |
| | | 4400 | | self.completedCount = CompleteCount; |
| | | 4401 | | self.completionSource.TrySetException(ex); |
| | | 4402 | | return; |
| | | 4403 | | } |
| | | 4404 | | |
| | | 4405 | | self.awaiter7.SourceOnCompleted(Completed7Delegate, self); |
| | | 4406 | | } |
| | | 4407 | | return; |
| | | 4408 | | COMPLETE: |
| | | 4409 | | self.completionSource.TrySetResult(false); |
| | | 4410 | | return; |
| | | 4411 | | } |
| | | 4412 | | |
| | | 4413 | | static void Completed8(object state) |
| | | 4414 | | { |
| | | 4415 | | var self = (_CombineLatest)state; |
| | | 4416 | | self.running8 = false; |
| | | 4417 | | |
| | | 4418 | | try |
| | | 4419 | | { |
| | | 4420 | | if (self.awaiter8.GetResult()) |
| | | 4421 | | { |
| | | 4422 | | self.hasCurrent8 = true; |
| | | 4423 | | self.current8 = self.enumerator8.Current; |
| | | 4424 | | goto SUCCESS; |
| | | 4425 | | } |
| | | 4426 | | else |
| | | 4427 | | { |
| | | 4428 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 4429 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 4430 | | { |
| | | 4431 | | goto COMPLETE; |
| | | 4432 | | } |
| | | 4433 | | return; |
| | | 4434 | | } |
| | | 4435 | | } |
| | | 4436 | | catch (Exception ex) |
| | | 4437 | | { |
| | | 4438 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 4439 | | self.completedCount = CompleteCount; |
| | | 4440 | | self.completionSource.TrySetException(ex); |
| | | 4441 | | return; |
| | | 4442 | | } |
| | | 4443 | | |
| | | 4444 | | SUCCESS: |
| | | 4445 | | if (!self.TrySetResult()) |
| | | 4446 | | { |
| | | 4447 | | if (self.syncRunning) return; |
| | | 4448 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 4449 | | try |
| | | 4450 | | { |
| | | 4451 | | self.awaiter8 = self.enumerator8.MoveNextAsync().GetAwaiter(); |
| | | 4452 | | } |
| | | 4453 | | catch (Exception ex) |
| | | 4454 | | { |
| | | 4455 | | self.completedCount = CompleteCount; |
| | | 4456 | | self.completionSource.TrySetException(ex); |
| | | 4457 | | return; |
| | | 4458 | | } |
| | | 4459 | | |
| | | 4460 | | self.awaiter8.SourceOnCompleted(Completed8Delegate, self); |
| | | 4461 | | } |
| | | 4462 | | return; |
| | | 4463 | | COMPLETE: |
| | | 4464 | | self.completionSource.TrySetResult(false); |
| | | 4465 | | return; |
| | | 4466 | | } |
| | | 4467 | | |
| | | 4468 | | static void Completed9(object state) |
| | | 4469 | | { |
| | | 4470 | | var self = (_CombineLatest)state; |
| | | 4471 | | self.running9 = false; |
| | | 4472 | | |
| | | 4473 | | try |
| | | 4474 | | { |
| | | 4475 | | if (self.awaiter9.GetResult()) |
| | | 4476 | | { |
| | | 4477 | | self.hasCurrent9 = true; |
| | | 4478 | | self.current9 = self.enumerator9.Current; |
| | | 4479 | | goto SUCCESS; |
| | | 4480 | | } |
| | | 4481 | | else |
| | | 4482 | | { |
| | | 4483 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 4484 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 4485 | | { |
| | | 4486 | | goto COMPLETE; |
| | | 4487 | | } |
| | | 4488 | | return; |
| | | 4489 | | } |
| | | 4490 | | } |
| | | 4491 | | catch (Exception ex) |
| | | 4492 | | { |
| | | 4493 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 4494 | | self.completedCount = CompleteCount; |
| | | 4495 | | self.completionSource.TrySetException(ex); |
| | | 4496 | | return; |
| | | 4497 | | } |
| | | 4498 | | |
| | | 4499 | | SUCCESS: |
| | | 4500 | | if (!self.TrySetResult()) |
| | | 4501 | | { |
| | | 4502 | | if (self.syncRunning) return; |
| | | 4503 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 4504 | | try |
| | | 4505 | | { |
| | | 4506 | | self.awaiter9 = self.enumerator9.MoveNextAsync().GetAwaiter(); |
| | | 4507 | | } |
| | | 4508 | | catch (Exception ex) |
| | | 4509 | | { |
| | | 4510 | | self.completedCount = CompleteCount; |
| | | 4511 | | self.completionSource.TrySetException(ex); |
| | | 4512 | | return; |
| | | 4513 | | } |
| | | 4514 | | |
| | | 4515 | | self.awaiter9.SourceOnCompleted(Completed9Delegate, self); |
| | | 4516 | | } |
| | | 4517 | | return; |
| | | 4518 | | COMPLETE: |
| | | 4519 | | self.completionSource.TrySetResult(false); |
| | | 4520 | | return; |
| | | 4521 | | } |
| | | 4522 | | |
| | | 4523 | | bool TrySetResult() |
| | | 4524 | | { |
| | | 4525 | | if (hasCurrent1 && hasCurrent2 && hasCurrent3 && hasCurrent4 && hasCurrent5 && hasCurrent6 && hasCurrent |
| | | 4526 | | { |
| | | 4527 | | result = resultSelector(current1, current2, current3, current4, current5, current6, current7, curren |
| | | 4528 | | completionSource.TrySetResult(true); |
| | | 4529 | | return true; |
| | | 4530 | | } |
| | | 4531 | | else |
| | | 4532 | | { |
| | | 4533 | | return false; |
| | | 4534 | | } |
| | | 4535 | | } |
| | | 4536 | | |
| | | 4537 | | public async UniTask DisposeAsync() |
| | | 4538 | | { |
| | | 4539 | | TaskTracker.RemoveTracking(this); |
| | | 4540 | | if (enumerator1 != null) |
| | | 4541 | | { |
| | | 4542 | | await enumerator1.DisposeAsync(); |
| | | 4543 | | } |
| | | 4544 | | if (enumerator2 != null) |
| | | 4545 | | { |
| | | 4546 | | await enumerator2.DisposeAsync(); |
| | | 4547 | | } |
| | | 4548 | | if (enumerator3 != null) |
| | | 4549 | | { |
| | | 4550 | | await enumerator3.DisposeAsync(); |
| | | 4551 | | } |
| | | 4552 | | if (enumerator4 != null) |
| | | 4553 | | { |
| | | 4554 | | await enumerator4.DisposeAsync(); |
| | | 4555 | | } |
| | | 4556 | | if (enumerator5 != null) |
| | | 4557 | | { |
| | | 4558 | | await enumerator5.DisposeAsync(); |
| | | 4559 | | } |
| | | 4560 | | if (enumerator6 != null) |
| | | 4561 | | { |
| | | 4562 | | await enumerator6.DisposeAsync(); |
| | | 4563 | | } |
| | | 4564 | | if (enumerator7 != null) |
| | | 4565 | | { |
| | | 4566 | | await enumerator7.DisposeAsync(); |
| | | 4567 | | } |
| | | 4568 | | if (enumerator8 != null) |
| | | 4569 | | { |
| | | 4570 | | await enumerator8.DisposeAsync(); |
| | | 4571 | | } |
| | | 4572 | | if (enumerator9 != null) |
| | | 4573 | | { |
| | | 4574 | | await enumerator9.DisposeAsync(); |
| | | 4575 | | } |
| | | 4576 | | } |
| | | 4577 | | } |
| | | 4578 | | } |
| | | 4579 | | |
| | | 4580 | | internal class CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> : IUniTaskAsyncEnumerable<TResult> |
| | | 4581 | | { |
| | | 4582 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 4583 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 4584 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 4585 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 4586 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 4587 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 4588 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 4589 | | readonly IUniTaskAsyncEnumerable<T8> source8; |
| | | 4590 | | readonly IUniTaskAsyncEnumerable<T9> source9; |
| | | 4591 | | readonly IUniTaskAsyncEnumerable<T10> source10; |
| | | 4592 | | |
| | | 4593 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> resultSelector; |
| | | 4594 | | |
| | | 4595 | | public CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyncEnum |
| | | 4596 | | { |
| | | 4597 | | this.source1 = source1; |
| | | 4598 | | this.source2 = source2; |
| | | 4599 | | this.source3 = source3; |
| | | 4600 | | this.source4 = source4; |
| | | 4601 | | this.source5 = source5; |
| | | 4602 | | this.source6 = source6; |
| | | 4603 | | this.source7 = source7; |
| | | 4604 | | this.source8 = source8; |
| | | 4605 | | this.source9 = source9; |
| | | 4606 | | this.source10 = source10; |
| | | 4607 | | |
| | | 4608 | | this.resultSelector = resultSelector; |
| | | 4609 | | } |
| | | 4610 | | |
| | | 4611 | | public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default) |
| | | 4612 | | { |
| | | 4613 | | return new _CombineLatest(source1, source2, source3, source4, source5, source6, source7, source8, source9, s |
| | | 4614 | | } |
| | | 4615 | | |
| | | 4616 | | class _CombineLatest : MoveNextSource, IUniTaskAsyncEnumerator<TResult> |
| | | 4617 | | { |
| | | 4618 | | static readonly Action<object> Completed1Delegate = Completed1; |
| | | 4619 | | static readonly Action<object> Completed2Delegate = Completed2; |
| | | 4620 | | static readonly Action<object> Completed3Delegate = Completed3; |
| | | 4621 | | static readonly Action<object> Completed4Delegate = Completed4; |
| | | 4622 | | static readonly Action<object> Completed5Delegate = Completed5; |
| | | 4623 | | static readonly Action<object> Completed6Delegate = Completed6; |
| | | 4624 | | static readonly Action<object> Completed7Delegate = Completed7; |
| | | 4625 | | static readonly Action<object> Completed8Delegate = Completed8; |
| | | 4626 | | static readonly Action<object> Completed9Delegate = Completed9; |
| | | 4627 | | static readonly Action<object> Completed10Delegate = Completed10; |
| | | 4628 | | const int CompleteCount = 10; |
| | | 4629 | | |
| | | 4630 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 4631 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 4632 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 4633 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 4634 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 4635 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 4636 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 4637 | | readonly IUniTaskAsyncEnumerable<T8> source8; |
| | | 4638 | | readonly IUniTaskAsyncEnumerable<T9> source9; |
| | | 4639 | | readonly IUniTaskAsyncEnumerable<T10> source10; |
| | | 4640 | | |
| | | 4641 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> resultSelector; |
| | | 4642 | | CancellationToken cancellationToken; |
| | | 4643 | | |
| | | 4644 | | IUniTaskAsyncEnumerator<T1> enumerator1; |
| | | 4645 | | UniTask<bool>.Awaiter awaiter1; |
| | | 4646 | | bool hasCurrent1; |
| | | 4647 | | bool running1; |
| | | 4648 | | T1 current1; |
| | | 4649 | | |
| | | 4650 | | IUniTaskAsyncEnumerator<T2> enumerator2; |
| | | 4651 | | UniTask<bool>.Awaiter awaiter2; |
| | | 4652 | | bool hasCurrent2; |
| | | 4653 | | bool running2; |
| | | 4654 | | T2 current2; |
| | | 4655 | | |
| | | 4656 | | IUniTaskAsyncEnumerator<T3> enumerator3; |
| | | 4657 | | UniTask<bool>.Awaiter awaiter3; |
| | | 4658 | | bool hasCurrent3; |
| | | 4659 | | bool running3; |
| | | 4660 | | T3 current3; |
| | | 4661 | | |
| | | 4662 | | IUniTaskAsyncEnumerator<T4> enumerator4; |
| | | 4663 | | UniTask<bool>.Awaiter awaiter4; |
| | | 4664 | | bool hasCurrent4; |
| | | 4665 | | bool running4; |
| | | 4666 | | T4 current4; |
| | | 4667 | | |
| | | 4668 | | IUniTaskAsyncEnumerator<T5> enumerator5; |
| | | 4669 | | UniTask<bool>.Awaiter awaiter5; |
| | | 4670 | | bool hasCurrent5; |
| | | 4671 | | bool running5; |
| | | 4672 | | T5 current5; |
| | | 4673 | | |
| | | 4674 | | IUniTaskAsyncEnumerator<T6> enumerator6; |
| | | 4675 | | UniTask<bool>.Awaiter awaiter6; |
| | | 4676 | | bool hasCurrent6; |
| | | 4677 | | bool running6; |
| | | 4678 | | T6 current6; |
| | | 4679 | | |
| | | 4680 | | IUniTaskAsyncEnumerator<T7> enumerator7; |
| | | 4681 | | UniTask<bool>.Awaiter awaiter7; |
| | | 4682 | | bool hasCurrent7; |
| | | 4683 | | bool running7; |
| | | 4684 | | T7 current7; |
| | | 4685 | | |
| | | 4686 | | IUniTaskAsyncEnumerator<T8> enumerator8; |
| | | 4687 | | UniTask<bool>.Awaiter awaiter8; |
| | | 4688 | | bool hasCurrent8; |
| | | 4689 | | bool running8; |
| | | 4690 | | T8 current8; |
| | | 4691 | | |
| | | 4692 | | IUniTaskAsyncEnumerator<T9> enumerator9; |
| | | 4693 | | UniTask<bool>.Awaiter awaiter9; |
| | | 4694 | | bool hasCurrent9; |
| | | 4695 | | bool running9; |
| | | 4696 | | T9 current9; |
| | | 4697 | | |
| | | 4698 | | IUniTaskAsyncEnumerator<T10> enumerator10; |
| | | 4699 | | UniTask<bool>.Awaiter awaiter10; |
| | | 4700 | | bool hasCurrent10; |
| | | 4701 | | bool running10; |
| | | 4702 | | T10 current10; |
| | | 4703 | | |
| | | 4704 | | int completedCount; |
| | | 4705 | | bool syncRunning; |
| | | 4706 | | TResult result; |
| | | 4707 | | |
| | | 4708 | | public _CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyn |
| | | 4709 | | { |
| | | 4710 | | this.source1 = source1; |
| | | 4711 | | this.source2 = source2; |
| | | 4712 | | this.source3 = source3; |
| | | 4713 | | this.source4 = source4; |
| | | 4714 | | this.source5 = source5; |
| | | 4715 | | this.source6 = source6; |
| | | 4716 | | this.source7 = source7; |
| | | 4717 | | this.source8 = source8; |
| | | 4718 | | this.source9 = source9; |
| | | 4719 | | this.source10 = source10; |
| | | 4720 | | |
| | | 4721 | | this.resultSelector = resultSelector; |
| | | 4722 | | this.cancellationToken = cancellationToken; |
| | | 4723 | | TaskTracker.TrackActiveTask(this, 3); |
| | | 4724 | | } |
| | | 4725 | | |
| | | 4726 | | public TResult Current => result; |
| | | 4727 | | |
| | | 4728 | | public UniTask<bool> MoveNextAsync() |
| | | 4729 | | { |
| | | 4730 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 4731 | | if (completedCount == CompleteCount) return CompletedTasks.False; |
| | | 4732 | | |
| | | 4733 | | if (enumerator1 == null) |
| | | 4734 | | { |
| | | 4735 | | enumerator1 = source1.GetAsyncEnumerator(cancellationToken); |
| | | 4736 | | enumerator2 = source2.GetAsyncEnumerator(cancellationToken); |
| | | 4737 | | enumerator3 = source3.GetAsyncEnumerator(cancellationToken); |
| | | 4738 | | enumerator4 = source4.GetAsyncEnumerator(cancellationToken); |
| | | 4739 | | enumerator5 = source5.GetAsyncEnumerator(cancellationToken); |
| | | 4740 | | enumerator6 = source6.GetAsyncEnumerator(cancellationToken); |
| | | 4741 | | enumerator7 = source7.GetAsyncEnumerator(cancellationToken); |
| | | 4742 | | enumerator8 = source8.GetAsyncEnumerator(cancellationToken); |
| | | 4743 | | enumerator9 = source9.GetAsyncEnumerator(cancellationToken); |
| | | 4744 | | enumerator10 = source10.GetAsyncEnumerator(cancellationToken); |
| | | 4745 | | } |
| | | 4746 | | |
| | | 4747 | | completionSource.Reset(); |
| | | 4748 | | |
| | | 4749 | | AGAIN: |
| | | 4750 | | syncRunning = true; |
| | | 4751 | | if (!running1) |
| | | 4752 | | { |
| | | 4753 | | running1 = true; |
| | | 4754 | | awaiter1 = enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 4755 | | if (awaiter1.IsCompleted) |
| | | 4756 | | { |
| | | 4757 | | Completed1(this); |
| | | 4758 | | } |
| | | 4759 | | else |
| | | 4760 | | { |
| | | 4761 | | awaiter1.SourceOnCompleted(Completed1Delegate, this); |
| | | 4762 | | } |
| | | 4763 | | } |
| | | 4764 | | if (!running2) |
| | | 4765 | | { |
| | | 4766 | | running2 = true; |
| | | 4767 | | awaiter2 = enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 4768 | | if (awaiter2.IsCompleted) |
| | | 4769 | | { |
| | | 4770 | | Completed2(this); |
| | | 4771 | | } |
| | | 4772 | | else |
| | | 4773 | | { |
| | | 4774 | | awaiter2.SourceOnCompleted(Completed2Delegate, this); |
| | | 4775 | | } |
| | | 4776 | | } |
| | | 4777 | | if (!running3) |
| | | 4778 | | { |
| | | 4779 | | running3 = true; |
| | | 4780 | | awaiter3 = enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 4781 | | if (awaiter3.IsCompleted) |
| | | 4782 | | { |
| | | 4783 | | Completed3(this); |
| | | 4784 | | } |
| | | 4785 | | else |
| | | 4786 | | { |
| | | 4787 | | awaiter3.SourceOnCompleted(Completed3Delegate, this); |
| | | 4788 | | } |
| | | 4789 | | } |
| | | 4790 | | if (!running4) |
| | | 4791 | | { |
| | | 4792 | | running4 = true; |
| | | 4793 | | awaiter4 = enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 4794 | | if (awaiter4.IsCompleted) |
| | | 4795 | | { |
| | | 4796 | | Completed4(this); |
| | | 4797 | | } |
| | | 4798 | | else |
| | | 4799 | | { |
| | | 4800 | | awaiter4.SourceOnCompleted(Completed4Delegate, this); |
| | | 4801 | | } |
| | | 4802 | | } |
| | | 4803 | | if (!running5) |
| | | 4804 | | { |
| | | 4805 | | running5 = true; |
| | | 4806 | | awaiter5 = enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 4807 | | if (awaiter5.IsCompleted) |
| | | 4808 | | { |
| | | 4809 | | Completed5(this); |
| | | 4810 | | } |
| | | 4811 | | else |
| | | 4812 | | { |
| | | 4813 | | awaiter5.SourceOnCompleted(Completed5Delegate, this); |
| | | 4814 | | } |
| | | 4815 | | } |
| | | 4816 | | if (!running6) |
| | | 4817 | | { |
| | | 4818 | | running6 = true; |
| | | 4819 | | awaiter6 = enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 4820 | | if (awaiter6.IsCompleted) |
| | | 4821 | | { |
| | | 4822 | | Completed6(this); |
| | | 4823 | | } |
| | | 4824 | | else |
| | | 4825 | | { |
| | | 4826 | | awaiter6.SourceOnCompleted(Completed6Delegate, this); |
| | | 4827 | | } |
| | | 4828 | | } |
| | | 4829 | | if (!running7) |
| | | 4830 | | { |
| | | 4831 | | running7 = true; |
| | | 4832 | | awaiter7 = enumerator7.MoveNextAsync().GetAwaiter(); |
| | | 4833 | | if (awaiter7.IsCompleted) |
| | | 4834 | | { |
| | | 4835 | | Completed7(this); |
| | | 4836 | | } |
| | | 4837 | | else |
| | | 4838 | | { |
| | | 4839 | | awaiter7.SourceOnCompleted(Completed7Delegate, this); |
| | | 4840 | | } |
| | | 4841 | | } |
| | | 4842 | | if (!running8) |
| | | 4843 | | { |
| | | 4844 | | running8 = true; |
| | | 4845 | | awaiter8 = enumerator8.MoveNextAsync().GetAwaiter(); |
| | | 4846 | | if (awaiter8.IsCompleted) |
| | | 4847 | | { |
| | | 4848 | | Completed8(this); |
| | | 4849 | | } |
| | | 4850 | | else |
| | | 4851 | | { |
| | | 4852 | | awaiter8.SourceOnCompleted(Completed8Delegate, this); |
| | | 4853 | | } |
| | | 4854 | | } |
| | | 4855 | | if (!running9) |
| | | 4856 | | { |
| | | 4857 | | running9 = true; |
| | | 4858 | | awaiter9 = enumerator9.MoveNextAsync().GetAwaiter(); |
| | | 4859 | | if (awaiter9.IsCompleted) |
| | | 4860 | | { |
| | | 4861 | | Completed9(this); |
| | | 4862 | | } |
| | | 4863 | | else |
| | | 4864 | | { |
| | | 4865 | | awaiter9.SourceOnCompleted(Completed9Delegate, this); |
| | | 4866 | | } |
| | | 4867 | | } |
| | | 4868 | | if (!running10) |
| | | 4869 | | { |
| | | 4870 | | running10 = true; |
| | | 4871 | | awaiter10 = enumerator10.MoveNextAsync().GetAwaiter(); |
| | | 4872 | | if (awaiter10.IsCompleted) |
| | | 4873 | | { |
| | | 4874 | | Completed10(this); |
| | | 4875 | | } |
| | | 4876 | | else |
| | | 4877 | | { |
| | | 4878 | | awaiter10.SourceOnCompleted(Completed10Delegate, this); |
| | | 4879 | | } |
| | | 4880 | | } |
| | | 4881 | | |
| | | 4882 | | if (!running1 || !running2 || !running3 || !running4 || !running5 || !running6 || !running7 || !running8 |
| | | 4883 | | { |
| | | 4884 | | goto AGAIN; |
| | | 4885 | | } |
| | | 4886 | | syncRunning = false; |
| | | 4887 | | |
| | | 4888 | | return new UniTask<bool>(this, completionSource.Version); |
| | | 4889 | | } |
| | | 4890 | | |
| | | 4891 | | static void Completed1(object state) |
| | | 4892 | | { |
| | | 4893 | | var self = (_CombineLatest)state; |
| | | 4894 | | self.running1 = false; |
| | | 4895 | | |
| | | 4896 | | try |
| | | 4897 | | { |
| | | 4898 | | if (self.awaiter1.GetResult()) |
| | | 4899 | | { |
| | | 4900 | | self.hasCurrent1 = true; |
| | | 4901 | | self.current1 = self.enumerator1.Current; |
| | | 4902 | | goto SUCCESS; |
| | | 4903 | | } |
| | | 4904 | | else |
| | | 4905 | | { |
| | | 4906 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 4907 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 4908 | | { |
| | | 4909 | | goto COMPLETE; |
| | | 4910 | | } |
| | | 4911 | | return; |
| | | 4912 | | } |
| | | 4913 | | } |
| | | 4914 | | catch (Exception ex) |
| | | 4915 | | { |
| | | 4916 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 4917 | | self.completedCount = CompleteCount; |
| | | 4918 | | self.completionSource.TrySetException(ex); |
| | | 4919 | | return; |
| | | 4920 | | } |
| | | 4921 | | |
| | | 4922 | | SUCCESS: |
| | | 4923 | | if (!self.TrySetResult()) |
| | | 4924 | | { |
| | | 4925 | | if (self.syncRunning) return; |
| | | 4926 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 4927 | | try |
| | | 4928 | | { |
| | | 4929 | | self.awaiter1 = self.enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 4930 | | } |
| | | 4931 | | catch (Exception ex) |
| | | 4932 | | { |
| | | 4933 | | self.completedCount = CompleteCount; |
| | | 4934 | | self.completionSource.TrySetException(ex); |
| | | 4935 | | return; |
| | | 4936 | | } |
| | | 4937 | | |
| | | 4938 | | self.awaiter1.SourceOnCompleted(Completed1Delegate, self); |
| | | 4939 | | } |
| | | 4940 | | return; |
| | | 4941 | | COMPLETE: |
| | | 4942 | | self.completionSource.TrySetResult(false); |
| | | 4943 | | return; |
| | | 4944 | | } |
| | | 4945 | | |
| | | 4946 | | static void Completed2(object state) |
| | | 4947 | | { |
| | | 4948 | | var self = (_CombineLatest)state; |
| | | 4949 | | self.running2 = false; |
| | | 4950 | | |
| | | 4951 | | try |
| | | 4952 | | { |
| | | 4953 | | if (self.awaiter2.GetResult()) |
| | | 4954 | | { |
| | | 4955 | | self.hasCurrent2 = true; |
| | | 4956 | | self.current2 = self.enumerator2.Current; |
| | | 4957 | | goto SUCCESS; |
| | | 4958 | | } |
| | | 4959 | | else |
| | | 4960 | | { |
| | | 4961 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 4962 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 4963 | | { |
| | | 4964 | | goto COMPLETE; |
| | | 4965 | | } |
| | | 4966 | | return; |
| | | 4967 | | } |
| | | 4968 | | } |
| | | 4969 | | catch (Exception ex) |
| | | 4970 | | { |
| | | 4971 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 4972 | | self.completedCount = CompleteCount; |
| | | 4973 | | self.completionSource.TrySetException(ex); |
| | | 4974 | | return; |
| | | 4975 | | } |
| | | 4976 | | |
| | | 4977 | | SUCCESS: |
| | | 4978 | | if (!self.TrySetResult()) |
| | | 4979 | | { |
| | | 4980 | | if (self.syncRunning) return; |
| | | 4981 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 4982 | | try |
| | | 4983 | | { |
| | | 4984 | | self.awaiter2 = self.enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 4985 | | } |
| | | 4986 | | catch (Exception ex) |
| | | 4987 | | { |
| | | 4988 | | self.completedCount = CompleteCount; |
| | | 4989 | | self.completionSource.TrySetException(ex); |
| | | 4990 | | return; |
| | | 4991 | | } |
| | | 4992 | | |
| | | 4993 | | self.awaiter2.SourceOnCompleted(Completed2Delegate, self); |
| | | 4994 | | } |
| | | 4995 | | return; |
| | | 4996 | | COMPLETE: |
| | | 4997 | | self.completionSource.TrySetResult(false); |
| | | 4998 | | return; |
| | | 4999 | | } |
| | | 5000 | | |
| | | 5001 | | static void Completed3(object state) |
| | | 5002 | | { |
| | | 5003 | | var self = (_CombineLatest)state; |
| | | 5004 | | self.running3 = false; |
| | | 5005 | | |
| | | 5006 | | try |
| | | 5007 | | { |
| | | 5008 | | if (self.awaiter3.GetResult()) |
| | | 5009 | | { |
| | | 5010 | | self.hasCurrent3 = true; |
| | | 5011 | | self.current3 = self.enumerator3.Current; |
| | | 5012 | | goto SUCCESS; |
| | | 5013 | | } |
| | | 5014 | | else |
| | | 5015 | | { |
| | | 5016 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 5017 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 5018 | | { |
| | | 5019 | | goto COMPLETE; |
| | | 5020 | | } |
| | | 5021 | | return; |
| | | 5022 | | } |
| | | 5023 | | } |
| | | 5024 | | catch (Exception ex) |
| | | 5025 | | { |
| | | 5026 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 5027 | | self.completedCount = CompleteCount; |
| | | 5028 | | self.completionSource.TrySetException(ex); |
| | | 5029 | | return; |
| | | 5030 | | } |
| | | 5031 | | |
| | | 5032 | | SUCCESS: |
| | | 5033 | | if (!self.TrySetResult()) |
| | | 5034 | | { |
| | | 5035 | | if (self.syncRunning) return; |
| | | 5036 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 5037 | | try |
| | | 5038 | | { |
| | | 5039 | | self.awaiter3 = self.enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 5040 | | } |
| | | 5041 | | catch (Exception ex) |
| | | 5042 | | { |
| | | 5043 | | self.completedCount = CompleteCount; |
| | | 5044 | | self.completionSource.TrySetException(ex); |
| | | 5045 | | return; |
| | | 5046 | | } |
| | | 5047 | | |
| | | 5048 | | self.awaiter3.SourceOnCompleted(Completed3Delegate, self); |
| | | 5049 | | } |
| | | 5050 | | return; |
| | | 5051 | | COMPLETE: |
| | | 5052 | | self.completionSource.TrySetResult(false); |
| | | 5053 | | return; |
| | | 5054 | | } |
| | | 5055 | | |
| | | 5056 | | static void Completed4(object state) |
| | | 5057 | | { |
| | | 5058 | | var self = (_CombineLatest)state; |
| | | 5059 | | self.running4 = false; |
| | | 5060 | | |
| | | 5061 | | try |
| | | 5062 | | { |
| | | 5063 | | if (self.awaiter4.GetResult()) |
| | | 5064 | | { |
| | | 5065 | | self.hasCurrent4 = true; |
| | | 5066 | | self.current4 = self.enumerator4.Current; |
| | | 5067 | | goto SUCCESS; |
| | | 5068 | | } |
| | | 5069 | | else |
| | | 5070 | | { |
| | | 5071 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 5072 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 5073 | | { |
| | | 5074 | | goto COMPLETE; |
| | | 5075 | | } |
| | | 5076 | | return; |
| | | 5077 | | } |
| | | 5078 | | } |
| | | 5079 | | catch (Exception ex) |
| | | 5080 | | { |
| | | 5081 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 5082 | | self.completedCount = CompleteCount; |
| | | 5083 | | self.completionSource.TrySetException(ex); |
| | | 5084 | | return; |
| | | 5085 | | } |
| | | 5086 | | |
| | | 5087 | | SUCCESS: |
| | | 5088 | | if (!self.TrySetResult()) |
| | | 5089 | | { |
| | | 5090 | | if (self.syncRunning) return; |
| | | 5091 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 5092 | | try |
| | | 5093 | | { |
| | | 5094 | | self.awaiter4 = self.enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 5095 | | } |
| | | 5096 | | catch (Exception ex) |
| | | 5097 | | { |
| | | 5098 | | self.completedCount = CompleteCount; |
| | | 5099 | | self.completionSource.TrySetException(ex); |
| | | 5100 | | return; |
| | | 5101 | | } |
| | | 5102 | | |
| | | 5103 | | self.awaiter4.SourceOnCompleted(Completed4Delegate, self); |
| | | 5104 | | } |
| | | 5105 | | return; |
| | | 5106 | | COMPLETE: |
| | | 5107 | | self.completionSource.TrySetResult(false); |
| | | 5108 | | return; |
| | | 5109 | | } |
| | | 5110 | | |
| | | 5111 | | static void Completed5(object state) |
| | | 5112 | | { |
| | | 5113 | | var self = (_CombineLatest)state; |
| | | 5114 | | self.running5 = false; |
| | | 5115 | | |
| | | 5116 | | try |
| | | 5117 | | { |
| | | 5118 | | if (self.awaiter5.GetResult()) |
| | | 5119 | | { |
| | | 5120 | | self.hasCurrent5 = true; |
| | | 5121 | | self.current5 = self.enumerator5.Current; |
| | | 5122 | | goto SUCCESS; |
| | | 5123 | | } |
| | | 5124 | | else |
| | | 5125 | | { |
| | | 5126 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 5127 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 5128 | | { |
| | | 5129 | | goto COMPLETE; |
| | | 5130 | | } |
| | | 5131 | | return; |
| | | 5132 | | } |
| | | 5133 | | } |
| | | 5134 | | catch (Exception ex) |
| | | 5135 | | { |
| | | 5136 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 5137 | | self.completedCount = CompleteCount; |
| | | 5138 | | self.completionSource.TrySetException(ex); |
| | | 5139 | | return; |
| | | 5140 | | } |
| | | 5141 | | |
| | | 5142 | | SUCCESS: |
| | | 5143 | | if (!self.TrySetResult()) |
| | | 5144 | | { |
| | | 5145 | | if (self.syncRunning) return; |
| | | 5146 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 5147 | | try |
| | | 5148 | | { |
| | | 5149 | | self.awaiter5 = self.enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 5150 | | } |
| | | 5151 | | catch (Exception ex) |
| | | 5152 | | { |
| | | 5153 | | self.completedCount = CompleteCount; |
| | | 5154 | | self.completionSource.TrySetException(ex); |
| | | 5155 | | return; |
| | | 5156 | | } |
| | | 5157 | | |
| | | 5158 | | self.awaiter5.SourceOnCompleted(Completed5Delegate, self); |
| | | 5159 | | } |
| | | 5160 | | return; |
| | | 5161 | | COMPLETE: |
| | | 5162 | | self.completionSource.TrySetResult(false); |
| | | 5163 | | return; |
| | | 5164 | | } |
| | | 5165 | | |
| | | 5166 | | static void Completed6(object state) |
| | | 5167 | | { |
| | | 5168 | | var self = (_CombineLatest)state; |
| | | 5169 | | self.running6 = false; |
| | | 5170 | | |
| | | 5171 | | try |
| | | 5172 | | { |
| | | 5173 | | if (self.awaiter6.GetResult()) |
| | | 5174 | | { |
| | | 5175 | | self.hasCurrent6 = true; |
| | | 5176 | | self.current6 = self.enumerator6.Current; |
| | | 5177 | | goto SUCCESS; |
| | | 5178 | | } |
| | | 5179 | | else |
| | | 5180 | | { |
| | | 5181 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 5182 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 5183 | | { |
| | | 5184 | | goto COMPLETE; |
| | | 5185 | | } |
| | | 5186 | | return; |
| | | 5187 | | } |
| | | 5188 | | } |
| | | 5189 | | catch (Exception ex) |
| | | 5190 | | { |
| | | 5191 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 5192 | | self.completedCount = CompleteCount; |
| | | 5193 | | self.completionSource.TrySetException(ex); |
| | | 5194 | | return; |
| | | 5195 | | } |
| | | 5196 | | |
| | | 5197 | | SUCCESS: |
| | | 5198 | | if (!self.TrySetResult()) |
| | | 5199 | | { |
| | | 5200 | | if (self.syncRunning) return; |
| | | 5201 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 5202 | | try |
| | | 5203 | | { |
| | | 5204 | | self.awaiter6 = self.enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 5205 | | } |
| | | 5206 | | catch (Exception ex) |
| | | 5207 | | { |
| | | 5208 | | self.completedCount = CompleteCount; |
| | | 5209 | | self.completionSource.TrySetException(ex); |
| | | 5210 | | return; |
| | | 5211 | | } |
| | | 5212 | | |
| | | 5213 | | self.awaiter6.SourceOnCompleted(Completed6Delegate, self); |
| | | 5214 | | } |
| | | 5215 | | return; |
| | | 5216 | | COMPLETE: |
| | | 5217 | | self.completionSource.TrySetResult(false); |
| | | 5218 | | return; |
| | | 5219 | | } |
| | | 5220 | | |
| | | 5221 | | static void Completed7(object state) |
| | | 5222 | | { |
| | | 5223 | | var self = (_CombineLatest)state; |
| | | 5224 | | self.running7 = false; |
| | | 5225 | | |
| | | 5226 | | try |
| | | 5227 | | { |
| | | 5228 | | if (self.awaiter7.GetResult()) |
| | | 5229 | | { |
| | | 5230 | | self.hasCurrent7 = true; |
| | | 5231 | | self.current7 = self.enumerator7.Current; |
| | | 5232 | | goto SUCCESS; |
| | | 5233 | | } |
| | | 5234 | | else |
| | | 5235 | | { |
| | | 5236 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 5237 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 5238 | | { |
| | | 5239 | | goto COMPLETE; |
| | | 5240 | | } |
| | | 5241 | | return; |
| | | 5242 | | } |
| | | 5243 | | } |
| | | 5244 | | catch (Exception ex) |
| | | 5245 | | { |
| | | 5246 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 5247 | | self.completedCount = CompleteCount; |
| | | 5248 | | self.completionSource.TrySetException(ex); |
| | | 5249 | | return; |
| | | 5250 | | } |
| | | 5251 | | |
| | | 5252 | | SUCCESS: |
| | | 5253 | | if (!self.TrySetResult()) |
| | | 5254 | | { |
| | | 5255 | | if (self.syncRunning) return; |
| | | 5256 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 5257 | | try |
| | | 5258 | | { |
| | | 5259 | | self.awaiter7 = self.enumerator7.MoveNextAsync().GetAwaiter(); |
| | | 5260 | | } |
| | | 5261 | | catch (Exception ex) |
| | | 5262 | | { |
| | | 5263 | | self.completedCount = CompleteCount; |
| | | 5264 | | self.completionSource.TrySetException(ex); |
| | | 5265 | | return; |
| | | 5266 | | } |
| | | 5267 | | |
| | | 5268 | | self.awaiter7.SourceOnCompleted(Completed7Delegate, self); |
| | | 5269 | | } |
| | | 5270 | | return; |
| | | 5271 | | COMPLETE: |
| | | 5272 | | self.completionSource.TrySetResult(false); |
| | | 5273 | | return; |
| | | 5274 | | } |
| | | 5275 | | |
| | | 5276 | | static void Completed8(object state) |
| | | 5277 | | { |
| | | 5278 | | var self = (_CombineLatest)state; |
| | | 5279 | | self.running8 = false; |
| | | 5280 | | |
| | | 5281 | | try |
| | | 5282 | | { |
| | | 5283 | | if (self.awaiter8.GetResult()) |
| | | 5284 | | { |
| | | 5285 | | self.hasCurrent8 = true; |
| | | 5286 | | self.current8 = self.enumerator8.Current; |
| | | 5287 | | goto SUCCESS; |
| | | 5288 | | } |
| | | 5289 | | else |
| | | 5290 | | { |
| | | 5291 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 5292 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 5293 | | { |
| | | 5294 | | goto COMPLETE; |
| | | 5295 | | } |
| | | 5296 | | return; |
| | | 5297 | | } |
| | | 5298 | | } |
| | | 5299 | | catch (Exception ex) |
| | | 5300 | | { |
| | | 5301 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 5302 | | self.completedCount = CompleteCount; |
| | | 5303 | | self.completionSource.TrySetException(ex); |
| | | 5304 | | return; |
| | | 5305 | | } |
| | | 5306 | | |
| | | 5307 | | SUCCESS: |
| | | 5308 | | if (!self.TrySetResult()) |
| | | 5309 | | { |
| | | 5310 | | if (self.syncRunning) return; |
| | | 5311 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 5312 | | try |
| | | 5313 | | { |
| | | 5314 | | self.awaiter8 = self.enumerator8.MoveNextAsync().GetAwaiter(); |
| | | 5315 | | } |
| | | 5316 | | catch (Exception ex) |
| | | 5317 | | { |
| | | 5318 | | self.completedCount = CompleteCount; |
| | | 5319 | | self.completionSource.TrySetException(ex); |
| | | 5320 | | return; |
| | | 5321 | | } |
| | | 5322 | | |
| | | 5323 | | self.awaiter8.SourceOnCompleted(Completed8Delegate, self); |
| | | 5324 | | } |
| | | 5325 | | return; |
| | | 5326 | | COMPLETE: |
| | | 5327 | | self.completionSource.TrySetResult(false); |
| | | 5328 | | return; |
| | | 5329 | | } |
| | | 5330 | | |
| | | 5331 | | static void Completed9(object state) |
| | | 5332 | | { |
| | | 5333 | | var self = (_CombineLatest)state; |
| | | 5334 | | self.running9 = false; |
| | | 5335 | | |
| | | 5336 | | try |
| | | 5337 | | { |
| | | 5338 | | if (self.awaiter9.GetResult()) |
| | | 5339 | | { |
| | | 5340 | | self.hasCurrent9 = true; |
| | | 5341 | | self.current9 = self.enumerator9.Current; |
| | | 5342 | | goto SUCCESS; |
| | | 5343 | | } |
| | | 5344 | | else |
| | | 5345 | | { |
| | | 5346 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 5347 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 5348 | | { |
| | | 5349 | | goto COMPLETE; |
| | | 5350 | | } |
| | | 5351 | | return; |
| | | 5352 | | } |
| | | 5353 | | } |
| | | 5354 | | catch (Exception ex) |
| | | 5355 | | { |
| | | 5356 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 5357 | | self.completedCount = CompleteCount; |
| | | 5358 | | self.completionSource.TrySetException(ex); |
| | | 5359 | | return; |
| | | 5360 | | } |
| | | 5361 | | |
| | | 5362 | | SUCCESS: |
| | | 5363 | | if (!self.TrySetResult()) |
| | | 5364 | | { |
| | | 5365 | | if (self.syncRunning) return; |
| | | 5366 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 5367 | | try |
| | | 5368 | | { |
| | | 5369 | | self.awaiter9 = self.enumerator9.MoveNextAsync().GetAwaiter(); |
| | | 5370 | | } |
| | | 5371 | | catch (Exception ex) |
| | | 5372 | | { |
| | | 5373 | | self.completedCount = CompleteCount; |
| | | 5374 | | self.completionSource.TrySetException(ex); |
| | | 5375 | | return; |
| | | 5376 | | } |
| | | 5377 | | |
| | | 5378 | | self.awaiter9.SourceOnCompleted(Completed9Delegate, self); |
| | | 5379 | | } |
| | | 5380 | | return; |
| | | 5381 | | COMPLETE: |
| | | 5382 | | self.completionSource.TrySetResult(false); |
| | | 5383 | | return; |
| | | 5384 | | } |
| | | 5385 | | |
| | | 5386 | | static void Completed10(object state) |
| | | 5387 | | { |
| | | 5388 | | var self = (_CombineLatest)state; |
| | | 5389 | | self.running10 = false; |
| | | 5390 | | |
| | | 5391 | | try |
| | | 5392 | | { |
| | | 5393 | | if (self.awaiter10.GetResult()) |
| | | 5394 | | { |
| | | 5395 | | self.hasCurrent10 = true; |
| | | 5396 | | self.current10 = self.enumerator10.Current; |
| | | 5397 | | goto SUCCESS; |
| | | 5398 | | } |
| | | 5399 | | else |
| | | 5400 | | { |
| | | 5401 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | | 5402 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 5403 | | { |
| | | 5404 | | goto COMPLETE; |
| | | 5405 | | } |
| | | 5406 | | return; |
| | | 5407 | | } |
| | | 5408 | | } |
| | | 5409 | | catch (Exception ex) |
| | | 5410 | | { |
| | | 5411 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | | 5412 | | self.completedCount = CompleteCount; |
| | | 5413 | | self.completionSource.TrySetException(ex); |
| | | 5414 | | return; |
| | | 5415 | | } |
| | | 5416 | | |
| | | 5417 | | SUCCESS: |
| | | 5418 | | if (!self.TrySetResult()) |
| | | 5419 | | { |
| | | 5420 | | if (self.syncRunning) return; |
| | | 5421 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | | 5422 | | try |
| | | 5423 | | { |
| | | 5424 | | self.awaiter10 = self.enumerator10.MoveNextAsync().GetAwaiter(); |
| | | 5425 | | } |
| | | 5426 | | catch (Exception ex) |
| | | 5427 | | { |
| | | 5428 | | self.completedCount = CompleteCount; |
| | | 5429 | | self.completionSource.TrySetException(ex); |
| | | 5430 | | return; |
| | | 5431 | | } |
| | | 5432 | | |
| | | 5433 | | self.awaiter10.SourceOnCompleted(Completed10Delegate, self); |
| | | 5434 | | } |
| | | 5435 | | return; |
| | | 5436 | | COMPLETE: |
| | | 5437 | | self.completionSource.TrySetResult(false); |
| | | 5438 | | return; |
| | | 5439 | | } |
| | | 5440 | | |
| | | 5441 | | bool TrySetResult() |
| | | 5442 | | { |
| | | 5443 | | if (hasCurrent1 && hasCurrent2 && hasCurrent3 && hasCurrent4 && hasCurrent5 && hasCurrent6 && hasCurrent |
| | | 5444 | | { |
| | | 5445 | | result = resultSelector(current1, current2, current3, current4, current5, current6, current7, curren |
| | | 5446 | | completionSource.TrySetResult(true); |
| | | 5447 | | return true; |
| | | 5448 | | } |
| | | 5449 | | else |
| | | 5450 | | { |
| | | 5451 | | return false; |
| | | 5452 | | } |
| | | 5453 | | } |
| | | 5454 | | |
| | | 5455 | | public async UniTask DisposeAsync() |
| | | 5456 | | { |
| | | 5457 | | TaskTracker.RemoveTracking(this); |
| | | 5458 | | if (enumerator1 != null) |
| | | 5459 | | { |
| | | 5460 | | await enumerator1.DisposeAsync(); |
| | | 5461 | | } |
| | | 5462 | | if (enumerator2 != null) |
| | | 5463 | | { |
| | | 5464 | | await enumerator2.DisposeAsync(); |
| | | 5465 | | } |
| | | 5466 | | if (enumerator3 != null) |
| | | 5467 | | { |
| | | 5468 | | await enumerator3.DisposeAsync(); |
| | | 5469 | | } |
| | | 5470 | | if (enumerator4 != null) |
| | | 5471 | | { |
| | | 5472 | | await enumerator4.DisposeAsync(); |
| | | 5473 | | } |
| | | 5474 | | if (enumerator5 != null) |
| | | 5475 | | { |
| | | 5476 | | await enumerator5.DisposeAsync(); |
| | | 5477 | | } |
| | | 5478 | | if (enumerator6 != null) |
| | | 5479 | | { |
| | | 5480 | | await enumerator6.DisposeAsync(); |
| | | 5481 | | } |
| | | 5482 | | if (enumerator7 != null) |
| | | 5483 | | { |
| | | 5484 | | await enumerator7.DisposeAsync(); |
| | | 5485 | | } |
| | | 5486 | | if (enumerator8 != null) |
| | | 5487 | | { |
| | | 5488 | | await enumerator8.DisposeAsync(); |
| | | 5489 | | } |
| | | 5490 | | if (enumerator9 != null) |
| | | 5491 | | { |
| | | 5492 | | await enumerator9.DisposeAsync(); |
| | | 5493 | | } |
| | | 5494 | | if (enumerator10 != null) |
| | | 5495 | | { |
| | | 5496 | | await enumerator10.DisposeAsync(); |
| | | 5497 | | } |
| | | 5498 | | } |
| | | 5499 | | } |
| | | 5500 | | } |
| | | 5501 | | |
| | | 5502 | | internal class CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult> : IUniTaskAsyncEnumerable<TResul |
| | | 5503 | | { |
| | | 5504 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 5505 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 5506 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 5507 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 5508 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 5509 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 5510 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 5511 | | readonly IUniTaskAsyncEnumerable<T8> source8; |
| | | 5512 | | readonly IUniTaskAsyncEnumerable<T9> source9; |
| | | 5513 | | readonly IUniTaskAsyncEnumerable<T10> source10; |
| | | 5514 | | readonly IUniTaskAsyncEnumerable<T11> source11; |
| | | 5515 | | |
| | | 5516 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult> resultSelector; |
| | | 5517 | | |
| | | 5518 | | public CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyncEnum |
| | | 5519 | | { |
| | | 5520 | | this.source1 = source1; |
| | | 5521 | | this.source2 = source2; |
| | | 5522 | | this.source3 = source3; |
| | | 5523 | | this.source4 = source4; |
| | | 5524 | | this.source5 = source5; |
| | | 5525 | | this.source6 = source6; |
| | | 5526 | | this.source7 = source7; |
| | | 5527 | | this.source8 = source8; |
| | | 5528 | | this.source9 = source9; |
| | | 5529 | | this.source10 = source10; |
| | | 5530 | | this.source11 = source11; |
| | | 5531 | | |
| | | 5532 | | this.resultSelector = resultSelector; |
| | | 5533 | | } |
| | | 5534 | | |
| | | 5535 | | public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default) |
| | | 5536 | | { |
| | | 5537 | | return new _CombineLatest(source1, source2, source3, source4, source5, source6, source7, source8, source9, s |
| | | 5538 | | } |
| | | 5539 | | |
| | | 5540 | | class _CombineLatest : MoveNextSource, IUniTaskAsyncEnumerator<TResult> |
| | | 5541 | | { |
| | | 5542 | | static readonly Action<object> Completed1Delegate = Completed1; |
| | | 5543 | | static readonly Action<object> Completed2Delegate = Completed2; |
| | | 5544 | | static readonly Action<object> Completed3Delegate = Completed3; |
| | | 5545 | | static readonly Action<object> Completed4Delegate = Completed4; |
| | | 5546 | | static readonly Action<object> Completed5Delegate = Completed5; |
| | | 5547 | | static readonly Action<object> Completed6Delegate = Completed6; |
| | | 5548 | | static readonly Action<object> Completed7Delegate = Completed7; |
| | | 5549 | | static readonly Action<object> Completed8Delegate = Completed8; |
| | | 5550 | | static readonly Action<object> Completed9Delegate = Completed9; |
| | | 5551 | | static readonly Action<object> Completed10Delegate = Completed10; |
| | | 5552 | | static readonly Action<object> Completed11Delegate = Completed11; |
| | | 5553 | | const int CompleteCount = 11; |
| | | 5554 | | |
| | | 5555 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 5556 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 5557 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 5558 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 5559 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 5560 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 5561 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 5562 | | readonly IUniTaskAsyncEnumerable<T8> source8; |
| | | 5563 | | readonly IUniTaskAsyncEnumerable<T9> source9; |
| | | 5564 | | readonly IUniTaskAsyncEnumerable<T10> source10; |
| | | 5565 | | readonly IUniTaskAsyncEnumerable<T11> source11; |
| | | 5566 | | |
| | | 5567 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult> resultSelector; |
| | | 5568 | | CancellationToken cancellationToken; |
| | | 5569 | | |
| | | 5570 | | IUniTaskAsyncEnumerator<T1> enumerator1; |
| | | 5571 | | UniTask<bool>.Awaiter awaiter1; |
| | | 5572 | | bool hasCurrent1; |
| | | 5573 | | bool running1; |
| | | 5574 | | T1 current1; |
| | | 5575 | | |
| | | 5576 | | IUniTaskAsyncEnumerator<T2> enumerator2; |
| | | 5577 | | UniTask<bool>.Awaiter awaiter2; |
| | | 5578 | | bool hasCurrent2; |
| | | 5579 | | bool running2; |
| | | 5580 | | T2 current2; |
| | | 5581 | | |
| | | 5582 | | IUniTaskAsyncEnumerator<T3> enumerator3; |
| | | 5583 | | UniTask<bool>.Awaiter awaiter3; |
| | | 5584 | | bool hasCurrent3; |
| | | 5585 | | bool running3; |
| | | 5586 | | T3 current3; |
| | | 5587 | | |
| | | 5588 | | IUniTaskAsyncEnumerator<T4> enumerator4; |
| | | 5589 | | UniTask<bool>.Awaiter awaiter4; |
| | | 5590 | | bool hasCurrent4; |
| | | 5591 | | bool running4; |
| | | 5592 | | T4 current4; |
| | | 5593 | | |
| | | 5594 | | IUniTaskAsyncEnumerator<T5> enumerator5; |
| | | 5595 | | UniTask<bool>.Awaiter awaiter5; |
| | | 5596 | | bool hasCurrent5; |
| | | 5597 | | bool running5; |
| | | 5598 | | T5 current5; |
| | | 5599 | | |
| | | 5600 | | IUniTaskAsyncEnumerator<T6> enumerator6; |
| | | 5601 | | UniTask<bool>.Awaiter awaiter6; |
| | | 5602 | | bool hasCurrent6; |
| | | 5603 | | bool running6; |
| | | 5604 | | T6 current6; |
| | | 5605 | | |
| | | 5606 | | IUniTaskAsyncEnumerator<T7> enumerator7; |
| | | 5607 | | UniTask<bool>.Awaiter awaiter7; |
| | | 5608 | | bool hasCurrent7; |
| | | 5609 | | bool running7; |
| | | 5610 | | T7 current7; |
| | | 5611 | | |
| | | 5612 | | IUniTaskAsyncEnumerator<T8> enumerator8; |
| | | 5613 | | UniTask<bool>.Awaiter awaiter8; |
| | | 5614 | | bool hasCurrent8; |
| | | 5615 | | bool running8; |
| | | 5616 | | T8 current8; |
| | | 5617 | | |
| | | 5618 | | IUniTaskAsyncEnumerator<T9> enumerator9; |
| | | 5619 | | UniTask<bool>.Awaiter awaiter9; |
| | | 5620 | | bool hasCurrent9; |
| | | 5621 | | bool running9; |
| | | 5622 | | T9 current9; |
| | | 5623 | | |
| | | 5624 | | IUniTaskAsyncEnumerator<T10> enumerator10; |
| | | 5625 | | UniTask<bool>.Awaiter awaiter10; |
| | | 5626 | | bool hasCurrent10; |
| | | 5627 | | bool running10; |
| | | 5628 | | T10 current10; |
| | | 5629 | | |
| | | 5630 | | IUniTaskAsyncEnumerator<T11> enumerator11; |
| | | 5631 | | UniTask<bool>.Awaiter awaiter11; |
| | | 5632 | | bool hasCurrent11; |
| | | 5633 | | bool running11; |
| | | 5634 | | T11 current11; |
| | | 5635 | | |
| | | 5636 | | int completedCount; |
| | | 5637 | | bool syncRunning; |
| | | 5638 | | TResult result; |
| | | 5639 | | |
| | | 5640 | | public _CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyn |
| | | 5641 | | { |
| | | 5642 | | this.source1 = source1; |
| | | 5643 | | this.source2 = source2; |
| | | 5644 | | this.source3 = source3; |
| | | 5645 | | this.source4 = source4; |
| | | 5646 | | this.source5 = source5; |
| | | 5647 | | this.source6 = source6; |
| | | 5648 | | this.source7 = source7; |
| | | 5649 | | this.source8 = source8; |
| | | 5650 | | this.source9 = source9; |
| | | 5651 | | this.source10 = source10; |
| | | 5652 | | this.source11 = source11; |
| | | 5653 | | |
| | | 5654 | | this.resultSelector = resultSelector; |
| | | 5655 | | this.cancellationToken = cancellationToken; |
| | | 5656 | | TaskTracker.TrackActiveTask(this, 3); |
| | | 5657 | | } |
| | | 5658 | | |
| | | 5659 | | public TResult Current => result; |
| | | 5660 | | |
| | | 5661 | | public UniTask<bool> MoveNextAsync() |
| | | 5662 | | { |
| | | 5663 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 5664 | | if (completedCount == CompleteCount) return CompletedTasks.False; |
| | | 5665 | | |
| | | 5666 | | if (enumerator1 == null) |
| | | 5667 | | { |
| | | 5668 | | enumerator1 = source1.GetAsyncEnumerator(cancellationToken); |
| | | 5669 | | enumerator2 = source2.GetAsyncEnumerator(cancellationToken); |
| | | 5670 | | enumerator3 = source3.GetAsyncEnumerator(cancellationToken); |
| | | 5671 | | enumerator4 = source4.GetAsyncEnumerator(cancellationToken); |
| | | 5672 | | enumerator5 = source5.GetAsyncEnumerator(cancellationToken); |
| | | 5673 | | enumerator6 = source6.GetAsyncEnumerator(cancellationToken); |
| | | 5674 | | enumerator7 = source7.GetAsyncEnumerator(cancellationToken); |
| | | 5675 | | enumerator8 = source8.GetAsyncEnumerator(cancellationToken); |
| | | 5676 | | enumerator9 = source9.GetAsyncEnumerator(cancellationToken); |
| | | 5677 | | enumerator10 = source10.GetAsyncEnumerator(cancellationToken); |
| | | 5678 | | enumerator11 = source11.GetAsyncEnumerator(cancellationToken); |
| | | 5679 | | } |
| | | 5680 | | |
| | | 5681 | | completionSource.Reset(); |
| | | 5682 | | |
| | | 5683 | | AGAIN: |
| | | 5684 | | syncRunning = true; |
| | | 5685 | | if (!running1) |
| | | 5686 | | { |
| | | 5687 | | running1 = true; |
| | | 5688 | | awaiter1 = enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 5689 | | if (awaiter1.IsCompleted) |
| | | 5690 | | { |
| | | 5691 | | Completed1(this); |
| | | 5692 | | } |
| | | 5693 | | else |
| | | 5694 | | { |
| | | 5695 | | awaiter1.SourceOnCompleted(Completed1Delegate, this); |
| | | 5696 | | } |
| | | 5697 | | } |
| | | 5698 | | if (!running2) |
| | | 5699 | | { |
| | | 5700 | | running2 = true; |
| | | 5701 | | awaiter2 = enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 5702 | | if (awaiter2.IsCompleted) |
| | | 5703 | | { |
| | | 5704 | | Completed2(this); |
| | | 5705 | | } |
| | | 5706 | | else |
| | | 5707 | | { |
| | | 5708 | | awaiter2.SourceOnCompleted(Completed2Delegate, this); |
| | | 5709 | | } |
| | | 5710 | | } |
| | | 5711 | | if (!running3) |
| | | 5712 | | { |
| | | 5713 | | running3 = true; |
| | | 5714 | | awaiter3 = enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 5715 | | if (awaiter3.IsCompleted) |
| | | 5716 | | { |
| | | 5717 | | Completed3(this); |
| | | 5718 | | } |
| | | 5719 | | else |
| | | 5720 | | { |
| | | 5721 | | awaiter3.SourceOnCompleted(Completed3Delegate, this); |
| | | 5722 | | } |
| | | 5723 | | } |
| | | 5724 | | if (!running4) |
| | | 5725 | | { |
| | | 5726 | | running4 = true; |
| | | 5727 | | awaiter4 = enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 5728 | | if (awaiter4.IsCompleted) |
| | | 5729 | | { |
| | | 5730 | | Completed4(this); |
| | | 5731 | | } |
| | | 5732 | | else |
| | | 5733 | | { |
| | | 5734 | | awaiter4.SourceOnCompleted(Completed4Delegate, this); |
| | | 5735 | | } |
| | | 5736 | | } |
| | | 5737 | | if (!running5) |
| | | 5738 | | { |
| | | 5739 | | running5 = true; |
| | | 5740 | | awaiter5 = enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 5741 | | if (awaiter5.IsCompleted) |
| | | 5742 | | { |
| | | 5743 | | Completed5(this); |
| | | 5744 | | } |
| | | 5745 | | else |
| | | 5746 | | { |
| | | 5747 | | awaiter5.SourceOnCompleted(Completed5Delegate, this); |
| | | 5748 | | } |
| | | 5749 | | } |
| | | 5750 | | if (!running6) |
| | | 5751 | | { |
| | | 5752 | | running6 = true; |
| | | 5753 | | awaiter6 = enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 5754 | | if (awaiter6.IsCompleted) |
| | | 5755 | | { |
| | | 5756 | | Completed6(this); |
| | | 5757 | | } |
| | | 5758 | | else |
| | | 5759 | | { |
| | | 5760 | | awaiter6.SourceOnCompleted(Completed6Delegate, this); |
| | | 5761 | | } |
| | | 5762 | | } |
| | | 5763 | | if (!running7) |
| | | 5764 | | { |
| | | 5765 | | running7 = true; |
| | | 5766 | | awaiter7 = enumerator7.MoveNextAsync().GetAwaiter(); |
| | | 5767 | | if (awaiter7.IsCompleted) |
| | | 5768 | | { |
| | | 5769 | | Completed7(this); |
| | | 5770 | | } |
| | | 5771 | | else |
| | | 5772 | | { |
| | | 5773 | | awaiter7.SourceOnCompleted(Completed7Delegate, this); |
| | | 5774 | | } |
| | | 5775 | | } |
| | | 5776 | | if (!running8) |
| | | 5777 | | { |
| | | 5778 | | running8 = true; |
| | | 5779 | | awaiter8 = enumerator8.MoveNextAsync().GetAwaiter(); |
| | | 5780 | | if (awaiter8.IsCompleted) |
| | | 5781 | | { |
| | | 5782 | | Completed8(this); |
| | | 5783 | | } |
| | | 5784 | | else |
| | | 5785 | | { |
| | | 5786 | | awaiter8.SourceOnCompleted(Completed8Delegate, this); |
| | | 5787 | | } |
| | | 5788 | | } |
| | | 5789 | | if (!running9) |
| | | 5790 | | { |
| | | 5791 | | running9 = true; |
| | | 5792 | | awaiter9 = enumerator9.MoveNextAsync().GetAwaiter(); |
| | | 5793 | | if (awaiter9.IsCompleted) |
| | | 5794 | | { |
| | | 5795 | | Completed9(this); |
| | | 5796 | | } |
| | | 5797 | | else |
| | | 5798 | | { |
| | | 5799 | | awaiter9.SourceOnCompleted(Completed9Delegate, this); |
| | | 5800 | | } |
| | | 5801 | | } |
| | | 5802 | | if (!running10) |
| | | 5803 | | { |
| | | 5804 | | running10 = true; |
| | | 5805 | | awaiter10 = enumerator10.MoveNextAsync().GetAwaiter(); |
| | | 5806 | | if (awaiter10.IsCompleted) |
| | | 5807 | | { |
| | | 5808 | | Completed10(this); |
| | | 5809 | | } |
| | | 5810 | | else |
| | | 5811 | | { |
| | | 5812 | | awaiter10.SourceOnCompleted(Completed10Delegate, this); |
| | | 5813 | | } |
| | | 5814 | | } |
| | | 5815 | | if (!running11) |
| | | 5816 | | { |
| | | 5817 | | running11 = true; |
| | | 5818 | | awaiter11 = enumerator11.MoveNextAsync().GetAwaiter(); |
| | | 5819 | | if (awaiter11.IsCompleted) |
| | | 5820 | | { |
| | | 5821 | | Completed11(this); |
| | | 5822 | | } |
| | | 5823 | | else |
| | | 5824 | | { |
| | | 5825 | | awaiter11.SourceOnCompleted(Completed11Delegate, this); |
| | | 5826 | | } |
| | | 5827 | | } |
| | | 5828 | | |
| | | 5829 | | if (!running1 || !running2 || !running3 || !running4 || !running5 || !running6 || !running7 || !running8 |
| | | 5830 | | { |
| | | 5831 | | goto AGAIN; |
| | | 5832 | | } |
| | | 5833 | | syncRunning = false; |
| | | 5834 | | |
| | | 5835 | | return new UniTask<bool>(this, completionSource.Version); |
| | | 5836 | | } |
| | | 5837 | | |
| | | 5838 | | static void Completed1(object state) |
| | | 5839 | | { |
| | | 5840 | | var self = (_CombineLatest)state; |
| | | 5841 | | self.running1 = false; |
| | | 5842 | | |
| | | 5843 | | try |
| | | 5844 | | { |
| | | 5845 | | if (self.awaiter1.GetResult()) |
| | | 5846 | | { |
| | | 5847 | | self.hasCurrent1 = true; |
| | | 5848 | | self.current1 = self.enumerator1.Current; |
| | | 5849 | | goto SUCCESS; |
| | | 5850 | | } |
| | | 5851 | | else |
| | | 5852 | | { |
| | | 5853 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 5854 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 5855 | | { |
| | | 5856 | | goto COMPLETE; |
| | | 5857 | | } |
| | | 5858 | | return; |
| | | 5859 | | } |
| | | 5860 | | } |
| | | 5861 | | catch (Exception ex) |
| | | 5862 | | { |
| | | 5863 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 5864 | | self.completedCount = CompleteCount; |
| | | 5865 | | self.completionSource.TrySetException(ex); |
| | | 5866 | | return; |
| | | 5867 | | } |
| | | 5868 | | |
| | | 5869 | | SUCCESS: |
| | | 5870 | | if (!self.TrySetResult()) |
| | | 5871 | | { |
| | | 5872 | | if (self.syncRunning) return; |
| | | 5873 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 5874 | | try |
| | | 5875 | | { |
| | | 5876 | | self.awaiter1 = self.enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 5877 | | } |
| | | 5878 | | catch (Exception ex) |
| | | 5879 | | { |
| | | 5880 | | self.completedCount = CompleteCount; |
| | | 5881 | | self.completionSource.TrySetException(ex); |
| | | 5882 | | return; |
| | | 5883 | | } |
| | | 5884 | | |
| | | 5885 | | self.awaiter1.SourceOnCompleted(Completed1Delegate, self); |
| | | 5886 | | } |
| | | 5887 | | return; |
| | | 5888 | | COMPLETE: |
| | | 5889 | | self.completionSource.TrySetResult(false); |
| | | 5890 | | return; |
| | | 5891 | | } |
| | | 5892 | | |
| | | 5893 | | static void Completed2(object state) |
| | | 5894 | | { |
| | | 5895 | | var self = (_CombineLatest)state; |
| | | 5896 | | self.running2 = false; |
| | | 5897 | | |
| | | 5898 | | try |
| | | 5899 | | { |
| | | 5900 | | if (self.awaiter2.GetResult()) |
| | | 5901 | | { |
| | | 5902 | | self.hasCurrent2 = true; |
| | | 5903 | | self.current2 = self.enumerator2.Current; |
| | | 5904 | | goto SUCCESS; |
| | | 5905 | | } |
| | | 5906 | | else |
| | | 5907 | | { |
| | | 5908 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 5909 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 5910 | | { |
| | | 5911 | | goto COMPLETE; |
| | | 5912 | | } |
| | | 5913 | | return; |
| | | 5914 | | } |
| | | 5915 | | } |
| | | 5916 | | catch (Exception ex) |
| | | 5917 | | { |
| | | 5918 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 5919 | | self.completedCount = CompleteCount; |
| | | 5920 | | self.completionSource.TrySetException(ex); |
| | | 5921 | | return; |
| | | 5922 | | } |
| | | 5923 | | |
| | | 5924 | | SUCCESS: |
| | | 5925 | | if (!self.TrySetResult()) |
| | | 5926 | | { |
| | | 5927 | | if (self.syncRunning) return; |
| | | 5928 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 5929 | | try |
| | | 5930 | | { |
| | | 5931 | | self.awaiter2 = self.enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 5932 | | } |
| | | 5933 | | catch (Exception ex) |
| | | 5934 | | { |
| | | 5935 | | self.completedCount = CompleteCount; |
| | | 5936 | | self.completionSource.TrySetException(ex); |
| | | 5937 | | return; |
| | | 5938 | | } |
| | | 5939 | | |
| | | 5940 | | self.awaiter2.SourceOnCompleted(Completed2Delegate, self); |
| | | 5941 | | } |
| | | 5942 | | return; |
| | | 5943 | | COMPLETE: |
| | | 5944 | | self.completionSource.TrySetResult(false); |
| | | 5945 | | return; |
| | | 5946 | | } |
| | | 5947 | | |
| | | 5948 | | static void Completed3(object state) |
| | | 5949 | | { |
| | | 5950 | | var self = (_CombineLatest)state; |
| | | 5951 | | self.running3 = false; |
| | | 5952 | | |
| | | 5953 | | try |
| | | 5954 | | { |
| | | 5955 | | if (self.awaiter3.GetResult()) |
| | | 5956 | | { |
| | | 5957 | | self.hasCurrent3 = true; |
| | | 5958 | | self.current3 = self.enumerator3.Current; |
| | | 5959 | | goto SUCCESS; |
| | | 5960 | | } |
| | | 5961 | | else |
| | | 5962 | | { |
| | | 5963 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 5964 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 5965 | | { |
| | | 5966 | | goto COMPLETE; |
| | | 5967 | | } |
| | | 5968 | | return; |
| | | 5969 | | } |
| | | 5970 | | } |
| | | 5971 | | catch (Exception ex) |
| | | 5972 | | { |
| | | 5973 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 5974 | | self.completedCount = CompleteCount; |
| | | 5975 | | self.completionSource.TrySetException(ex); |
| | | 5976 | | return; |
| | | 5977 | | } |
| | | 5978 | | |
| | | 5979 | | SUCCESS: |
| | | 5980 | | if (!self.TrySetResult()) |
| | | 5981 | | { |
| | | 5982 | | if (self.syncRunning) return; |
| | | 5983 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 5984 | | try |
| | | 5985 | | { |
| | | 5986 | | self.awaiter3 = self.enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 5987 | | } |
| | | 5988 | | catch (Exception ex) |
| | | 5989 | | { |
| | | 5990 | | self.completedCount = CompleteCount; |
| | | 5991 | | self.completionSource.TrySetException(ex); |
| | | 5992 | | return; |
| | | 5993 | | } |
| | | 5994 | | |
| | | 5995 | | self.awaiter3.SourceOnCompleted(Completed3Delegate, self); |
| | | 5996 | | } |
| | | 5997 | | return; |
| | | 5998 | | COMPLETE: |
| | | 5999 | | self.completionSource.TrySetResult(false); |
| | | 6000 | | return; |
| | | 6001 | | } |
| | | 6002 | | |
| | | 6003 | | static void Completed4(object state) |
| | | 6004 | | { |
| | | 6005 | | var self = (_CombineLatest)state; |
| | | 6006 | | self.running4 = false; |
| | | 6007 | | |
| | | 6008 | | try |
| | | 6009 | | { |
| | | 6010 | | if (self.awaiter4.GetResult()) |
| | | 6011 | | { |
| | | 6012 | | self.hasCurrent4 = true; |
| | | 6013 | | self.current4 = self.enumerator4.Current; |
| | | 6014 | | goto SUCCESS; |
| | | 6015 | | } |
| | | 6016 | | else |
| | | 6017 | | { |
| | | 6018 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 6019 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 6020 | | { |
| | | 6021 | | goto COMPLETE; |
| | | 6022 | | } |
| | | 6023 | | return; |
| | | 6024 | | } |
| | | 6025 | | } |
| | | 6026 | | catch (Exception ex) |
| | | 6027 | | { |
| | | 6028 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 6029 | | self.completedCount = CompleteCount; |
| | | 6030 | | self.completionSource.TrySetException(ex); |
| | | 6031 | | return; |
| | | 6032 | | } |
| | | 6033 | | |
| | | 6034 | | SUCCESS: |
| | | 6035 | | if (!self.TrySetResult()) |
| | | 6036 | | { |
| | | 6037 | | if (self.syncRunning) return; |
| | | 6038 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 6039 | | try |
| | | 6040 | | { |
| | | 6041 | | self.awaiter4 = self.enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 6042 | | } |
| | | 6043 | | catch (Exception ex) |
| | | 6044 | | { |
| | | 6045 | | self.completedCount = CompleteCount; |
| | | 6046 | | self.completionSource.TrySetException(ex); |
| | | 6047 | | return; |
| | | 6048 | | } |
| | | 6049 | | |
| | | 6050 | | self.awaiter4.SourceOnCompleted(Completed4Delegate, self); |
| | | 6051 | | } |
| | | 6052 | | return; |
| | | 6053 | | COMPLETE: |
| | | 6054 | | self.completionSource.TrySetResult(false); |
| | | 6055 | | return; |
| | | 6056 | | } |
| | | 6057 | | |
| | | 6058 | | static void Completed5(object state) |
| | | 6059 | | { |
| | | 6060 | | var self = (_CombineLatest)state; |
| | | 6061 | | self.running5 = false; |
| | | 6062 | | |
| | | 6063 | | try |
| | | 6064 | | { |
| | | 6065 | | if (self.awaiter5.GetResult()) |
| | | 6066 | | { |
| | | 6067 | | self.hasCurrent5 = true; |
| | | 6068 | | self.current5 = self.enumerator5.Current; |
| | | 6069 | | goto SUCCESS; |
| | | 6070 | | } |
| | | 6071 | | else |
| | | 6072 | | { |
| | | 6073 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 6074 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 6075 | | { |
| | | 6076 | | goto COMPLETE; |
| | | 6077 | | } |
| | | 6078 | | return; |
| | | 6079 | | } |
| | | 6080 | | } |
| | | 6081 | | catch (Exception ex) |
| | | 6082 | | { |
| | | 6083 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 6084 | | self.completedCount = CompleteCount; |
| | | 6085 | | self.completionSource.TrySetException(ex); |
| | | 6086 | | return; |
| | | 6087 | | } |
| | | 6088 | | |
| | | 6089 | | SUCCESS: |
| | | 6090 | | if (!self.TrySetResult()) |
| | | 6091 | | { |
| | | 6092 | | if (self.syncRunning) return; |
| | | 6093 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 6094 | | try |
| | | 6095 | | { |
| | | 6096 | | self.awaiter5 = self.enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 6097 | | } |
| | | 6098 | | catch (Exception ex) |
| | | 6099 | | { |
| | | 6100 | | self.completedCount = CompleteCount; |
| | | 6101 | | self.completionSource.TrySetException(ex); |
| | | 6102 | | return; |
| | | 6103 | | } |
| | | 6104 | | |
| | | 6105 | | self.awaiter5.SourceOnCompleted(Completed5Delegate, self); |
| | | 6106 | | } |
| | | 6107 | | return; |
| | | 6108 | | COMPLETE: |
| | | 6109 | | self.completionSource.TrySetResult(false); |
| | | 6110 | | return; |
| | | 6111 | | } |
| | | 6112 | | |
| | | 6113 | | static void Completed6(object state) |
| | | 6114 | | { |
| | | 6115 | | var self = (_CombineLatest)state; |
| | | 6116 | | self.running6 = false; |
| | | 6117 | | |
| | | 6118 | | try |
| | | 6119 | | { |
| | | 6120 | | if (self.awaiter6.GetResult()) |
| | | 6121 | | { |
| | | 6122 | | self.hasCurrent6 = true; |
| | | 6123 | | self.current6 = self.enumerator6.Current; |
| | | 6124 | | goto SUCCESS; |
| | | 6125 | | } |
| | | 6126 | | else |
| | | 6127 | | { |
| | | 6128 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 6129 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 6130 | | { |
| | | 6131 | | goto COMPLETE; |
| | | 6132 | | } |
| | | 6133 | | return; |
| | | 6134 | | } |
| | | 6135 | | } |
| | | 6136 | | catch (Exception ex) |
| | | 6137 | | { |
| | | 6138 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 6139 | | self.completedCount = CompleteCount; |
| | | 6140 | | self.completionSource.TrySetException(ex); |
| | | 6141 | | return; |
| | | 6142 | | } |
| | | 6143 | | |
| | | 6144 | | SUCCESS: |
| | | 6145 | | if (!self.TrySetResult()) |
| | | 6146 | | { |
| | | 6147 | | if (self.syncRunning) return; |
| | | 6148 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 6149 | | try |
| | | 6150 | | { |
| | | 6151 | | self.awaiter6 = self.enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 6152 | | } |
| | | 6153 | | catch (Exception ex) |
| | | 6154 | | { |
| | | 6155 | | self.completedCount = CompleteCount; |
| | | 6156 | | self.completionSource.TrySetException(ex); |
| | | 6157 | | return; |
| | | 6158 | | } |
| | | 6159 | | |
| | | 6160 | | self.awaiter6.SourceOnCompleted(Completed6Delegate, self); |
| | | 6161 | | } |
| | | 6162 | | return; |
| | | 6163 | | COMPLETE: |
| | | 6164 | | self.completionSource.TrySetResult(false); |
| | | 6165 | | return; |
| | | 6166 | | } |
| | | 6167 | | |
| | | 6168 | | static void Completed7(object state) |
| | | 6169 | | { |
| | | 6170 | | var self = (_CombineLatest)state; |
| | | 6171 | | self.running7 = false; |
| | | 6172 | | |
| | | 6173 | | try |
| | | 6174 | | { |
| | | 6175 | | if (self.awaiter7.GetResult()) |
| | | 6176 | | { |
| | | 6177 | | self.hasCurrent7 = true; |
| | | 6178 | | self.current7 = self.enumerator7.Current; |
| | | 6179 | | goto SUCCESS; |
| | | 6180 | | } |
| | | 6181 | | else |
| | | 6182 | | { |
| | | 6183 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 6184 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 6185 | | { |
| | | 6186 | | goto COMPLETE; |
| | | 6187 | | } |
| | | 6188 | | return; |
| | | 6189 | | } |
| | | 6190 | | } |
| | | 6191 | | catch (Exception ex) |
| | | 6192 | | { |
| | | 6193 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 6194 | | self.completedCount = CompleteCount; |
| | | 6195 | | self.completionSource.TrySetException(ex); |
| | | 6196 | | return; |
| | | 6197 | | } |
| | | 6198 | | |
| | | 6199 | | SUCCESS: |
| | | 6200 | | if (!self.TrySetResult()) |
| | | 6201 | | { |
| | | 6202 | | if (self.syncRunning) return; |
| | | 6203 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 6204 | | try |
| | | 6205 | | { |
| | | 6206 | | self.awaiter7 = self.enumerator7.MoveNextAsync().GetAwaiter(); |
| | | 6207 | | } |
| | | 6208 | | catch (Exception ex) |
| | | 6209 | | { |
| | | 6210 | | self.completedCount = CompleteCount; |
| | | 6211 | | self.completionSource.TrySetException(ex); |
| | | 6212 | | return; |
| | | 6213 | | } |
| | | 6214 | | |
| | | 6215 | | self.awaiter7.SourceOnCompleted(Completed7Delegate, self); |
| | | 6216 | | } |
| | | 6217 | | return; |
| | | 6218 | | COMPLETE: |
| | | 6219 | | self.completionSource.TrySetResult(false); |
| | | 6220 | | return; |
| | | 6221 | | } |
| | | 6222 | | |
| | | 6223 | | static void Completed8(object state) |
| | | 6224 | | { |
| | | 6225 | | var self = (_CombineLatest)state; |
| | | 6226 | | self.running8 = false; |
| | | 6227 | | |
| | | 6228 | | try |
| | | 6229 | | { |
| | | 6230 | | if (self.awaiter8.GetResult()) |
| | | 6231 | | { |
| | | 6232 | | self.hasCurrent8 = true; |
| | | 6233 | | self.current8 = self.enumerator8.Current; |
| | | 6234 | | goto SUCCESS; |
| | | 6235 | | } |
| | | 6236 | | else |
| | | 6237 | | { |
| | | 6238 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 6239 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 6240 | | { |
| | | 6241 | | goto COMPLETE; |
| | | 6242 | | } |
| | | 6243 | | return; |
| | | 6244 | | } |
| | | 6245 | | } |
| | | 6246 | | catch (Exception ex) |
| | | 6247 | | { |
| | | 6248 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 6249 | | self.completedCount = CompleteCount; |
| | | 6250 | | self.completionSource.TrySetException(ex); |
| | | 6251 | | return; |
| | | 6252 | | } |
| | | 6253 | | |
| | | 6254 | | SUCCESS: |
| | | 6255 | | if (!self.TrySetResult()) |
| | | 6256 | | { |
| | | 6257 | | if (self.syncRunning) return; |
| | | 6258 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 6259 | | try |
| | | 6260 | | { |
| | | 6261 | | self.awaiter8 = self.enumerator8.MoveNextAsync().GetAwaiter(); |
| | | 6262 | | } |
| | | 6263 | | catch (Exception ex) |
| | | 6264 | | { |
| | | 6265 | | self.completedCount = CompleteCount; |
| | | 6266 | | self.completionSource.TrySetException(ex); |
| | | 6267 | | return; |
| | | 6268 | | } |
| | | 6269 | | |
| | | 6270 | | self.awaiter8.SourceOnCompleted(Completed8Delegate, self); |
| | | 6271 | | } |
| | | 6272 | | return; |
| | | 6273 | | COMPLETE: |
| | | 6274 | | self.completionSource.TrySetResult(false); |
| | | 6275 | | return; |
| | | 6276 | | } |
| | | 6277 | | |
| | | 6278 | | static void Completed9(object state) |
| | | 6279 | | { |
| | | 6280 | | var self = (_CombineLatest)state; |
| | | 6281 | | self.running9 = false; |
| | | 6282 | | |
| | | 6283 | | try |
| | | 6284 | | { |
| | | 6285 | | if (self.awaiter9.GetResult()) |
| | | 6286 | | { |
| | | 6287 | | self.hasCurrent9 = true; |
| | | 6288 | | self.current9 = self.enumerator9.Current; |
| | | 6289 | | goto SUCCESS; |
| | | 6290 | | } |
| | | 6291 | | else |
| | | 6292 | | { |
| | | 6293 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 6294 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 6295 | | { |
| | | 6296 | | goto COMPLETE; |
| | | 6297 | | } |
| | | 6298 | | return; |
| | | 6299 | | } |
| | | 6300 | | } |
| | | 6301 | | catch (Exception ex) |
| | | 6302 | | { |
| | | 6303 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 6304 | | self.completedCount = CompleteCount; |
| | | 6305 | | self.completionSource.TrySetException(ex); |
| | | 6306 | | return; |
| | | 6307 | | } |
| | | 6308 | | |
| | | 6309 | | SUCCESS: |
| | | 6310 | | if (!self.TrySetResult()) |
| | | 6311 | | { |
| | | 6312 | | if (self.syncRunning) return; |
| | | 6313 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 6314 | | try |
| | | 6315 | | { |
| | | 6316 | | self.awaiter9 = self.enumerator9.MoveNextAsync().GetAwaiter(); |
| | | 6317 | | } |
| | | 6318 | | catch (Exception ex) |
| | | 6319 | | { |
| | | 6320 | | self.completedCount = CompleteCount; |
| | | 6321 | | self.completionSource.TrySetException(ex); |
| | | 6322 | | return; |
| | | 6323 | | } |
| | | 6324 | | |
| | | 6325 | | self.awaiter9.SourceOnCompleted(Completed9Delegate, self); |
| | | 6326 | | } |
| | | 6327 | | return; |
| | | 6328 | | COMPLETE: |
| | | 6329 | | self.completionSource.TrySetResult(false); |
| | | 6330 | | return; |
| | | 6331 | | } |
| | | 6332 | | |
| | | 6333 | | static void Completed10(object state) |
| | | 6334 | | { |
| | | 6335 | | var self = (_CombineLatest)state; |
| | | 6336 | | self.running10 = false; |
| | | 6337 | | |
| | | 6338 | | try |
| | | 6339 | | { |
| | | 6340 | | if (self.awaiter10.GetResult()) |
| | | 6341 | | { |
| | | 6342 | | self.hasCurrent10 = true; |
| | | 6343 | | self.current10 = self.enumerator10.Current; |
| | | 6344 | | goto SUCCESS; |
| | | 6345 | | } |
| | | 6346 | | else |
| | | 6347 | | { |
| | | 6348 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | | 6349 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 6350 | | { |
| | | 6351 | | goto COMPLETE; |
| | | 6352 | | } |
| | | 6353 | | return; |
| | | 6354 | | } |
| | | 6355 | | } |
| | | 6356 | | catch (Exception ex) |
| | | 6357 | | { |
| | | 6358 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | | 6359 | | self.completedCount = CompleteCount; |
| | | 6360 | | self.completionSource.TrySetException(ex); |
| | | 6361 | | return; |
| | | 6362 | | } |
| | | 6363 | | |
| | | 6364 | | SUCCESS: |
| | | 6365 | | if (!self.TrySetResult()) |
| | | 6366 | | { |
| | | 6367 | | if (self.syncRunning) return; |
| | | 6368 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | | 6369 | | try |
| | | 6370 | | { |
| | | 6371 | | self.awaiter10 = self.enumerator10.MoveNextAsync().GetAwaiter(); |
| | | 6372 | | } |
| | | 6373 | | catch (Exception ex) |
| | | 6374 | | { |
| | | 6375 | | self.completedCount = CompleteCount; |
| | | 6376 | | self.completionSource.TrySetException(ex); |
| | | 6377 | | return; |
| | | 6378 | | } |
| | | 6379 | | |
| | | 6380 | | self.awaiter10.SourceOnCompleted(Completed10Delegate, self); |
| | | 6381 | | } |
| | | 6382 | | return; |
| | | 6383 | | COMPLETE: |
| | | 6384 | | self.completionSource.TrySetResult(false); |
| | | 6385 | | return; |
| | | 6386 | | } |
| | | 6387 | | |
| | | 6388 | | static void Completed11(object state) |
| | | 6389 | | { |
| | | 6390 | | var self = (_CombineLatest)state; |
| | | 6391 | | self.running11 = false; |
| | | 6392 | | |
| | | 6393 | | try |
| | | 6394 | | { |
| | | 6395 | | if (self.awaiter11.GetResult()) |
| | | 6396 | | { |
| | | 6397 | | self.hasCurrent11 = true; |
| | | 6398 | | self.current11 = self.enumerator11.Current; |
| | | 6399 | | goto SUCCESS; |
| | | 6400 | | } |
| | | 6401 | | else |
| | | 6402 | | { |
| | | 6403 | | self.running11 = true; // as complete, no more call MoveNextAsync. |
| | | 6404 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 6405 | | { |
| | | 6406 | | goto COMPLETE; |
| | | 6407 | | } |
| | | 6408 | | return; |
| | | 6409 | | } |
| | | 6410 | | } |
| | | 6411 | | catch (Exception ex) |
| | | 6412 | | { |
| | | 6413 | | self.running11 = true; // as complete, no more call MoveNextAsync. |
| | | 6414 | | self.completedCount = CompleteCount; |
| | | 6415 | | self.completionSource.TrySetException(ex); |
| | | 6416 | | return; |
| | | 6417 | | } |
| | | 6418 | | |
| | | 6419 | | SUCCESS: |
| | | 6420 | | if (!self.TrySetResult()) |
| | | 6421 | | { |
| | | 6422 | | if (self.syncRunning) return; |
| | | 6423 | | self.running11 = true; // as complete, no more call MoveNextAsync. |
| | | 6424 | | try |
| | | 6425 | | { |
| | | 6426 | | self.awaiter11 = self.enumerator11.MoveNextAsync().GetAwaiter(); |
| | | 6427 | | } |
| | | 6428 | | catch (Exception ex) |
| | | 6429 | | { |
| | | 6430 | | self.completedCount = CompleteCount; |
| | | 6431 | | self.completionSource.TrySetException(ex); |
| | | 6432 | | return; |
| | | 6433 | | } |
| | | 6434 | | |
| | | 6435 | | self.awaiter11.SourceOnCompleted(Completed11Delegate, self); |
| | | 6436 | | } |
| | | 6437 | | return; |
| | | 6438 | | COMPLETE: |
| | | 6439 | | self.completionSource.TrySetResult(false); |
| | | 6440 | | return; |
| | | 6441 | | } |
| | | 6442 | | |
| | | 6443 | | bool TrySetResult() |
| | | 6444 | | { |
| | | 6445 | | if (hasCurrent1 && hasCurrent2 && hasCurrent3 && hasCurrent4 && hasCurrent5 && hasCurrent6 && hasCurrent |
| | | 6446 | | { |
| | | 6447 | | result = resultSelector(current1, current2, current3, current4, current5, current6, current7, curren |
| | | 6448 | | completionSource.TrySetResult(true); |
| | | 6449 | | return true; |
| | | 6450 | | } |
| | | 6451 | | else |
| | | 6452 | | { |
| | | 6453 | | return false; |
| | | 6454 | | } |
| | | 6455 | | } |
| | | 6456 | | |
| | | 6457 | | public async UniTask DisposeAsync() |
| | | 6458 | | { |
| | | 6459 | | TaskTracker.RemoveTracking(this); |
| | | 6460 | | if (enumerator1 != null) |
| | | 6461 | | { |
| | | 6462 | | await enumerator1.DisposeAsync(); |
| | | 6463 | | } |
| | | 6464 | | if (enumerator2 != null) |
| | | 6465 | | { |
| | | 6466 | | await enumerator2.DisposeAsync(); |
| | | 6467 | | } |
| | | 6468 | | if (enumerator3 != null) |
| | | 6469 | | { |
| | | 6470 | | await enumerator3.DisposeAsync(); |
| | | 6471 | | } |
| | | 6472 | | if (enumerator4 != null) |
| | | 6473 | | { |
| | | 6474 | | await enumerator4.DisposeAsync(); |
| | | 6475 | | } |
| | | 6476 | | if (enumerator5 != null) |
| | | 6477 | | { |
| | | 6478 | | await enumerator5.DisposeAsync(); |
| | | 6479 | | } |
| | | 6480 | | if (enumerator6 != null) |
| | | 6481 | | { |
| | | 6482 | | await enumerator6.DisposeAsync(); |
| | | 6483 | | } |
| | | 6484 | | if (enumerator7 != null) |
| | | 6485 | | { |
| | | 6486 | | await enumerator7.DisposeAsync(); |
| | | 6487 | | } |
| | | 6488 | | if (enumerator8 != null) |
| | | 6489 | | { |
| | | 6490 | | await enumerator8.DisposeAsync(); |
| | | 6491 | | } |
| | | 6492 | | if (enumerator9 != null) |
| | | 6493 | | { |
| | | 6494 | | await enumerator9.DisposeAsync(); |
| | | 6495 | | } |
| | | 6496 | | if (enumerator10 != null) |
| | | 6497 | | { |
| | | 6498 | | await enumerator10.DisposeAsync(); |
| | | 6499 | | } |
| | | 6500 | | if (enumerator11 != null) |
| | | 6501 | | { |
| | | 6502 | | await enumerator11.DisposeAsync(); |
| | | 6503 | | } |
| | | 6504 | | } |
| | | 6505 | | } |
| | | 6506 | | } |
| | | 6507 | | |
| | | 6508 | | internal class CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> : IUniTaskAsyncEnumerable<T |
| | | 6509 | | { |
| | | 6510 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 6511 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 6512 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 6513 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 6514 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 6515 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 6516 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 6517 | | readonly IUniTaskAsyncEnumerable<T8> source8; |
| | | 6518 | | readonly IUniTaskAsyncEnumerable<T9> source9; |
| | | 6519 | | readonly IUniTaskAsyncEnumerable<T10> source10; |
| | | 6520 | | readonly IUniTaskAsyncEnumerable<T11> source11; |
| | | 6521 | | readonly IUniTaskAsyncEnumerable<T12> source12; |
| | | 6522 | | |
| | | 6523 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> resultSelector; |
| | | 6524 | | |
| | | 6525 | | public CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyncEnum |
| | | 6526 | | { |
| | | 6527 | | this.source1 = source1; |
| | | 6528 | | this.source2 = source2; |
| | | 6529 | | this.source3 = source3; |
| | | 6530 | | this.source4 = source4; |
| | | 6531 | | this.source5 = source5; |
| | | 6532 | | this.source6 = source6; |
| | | 6533 | | this.source7 = source7; |
| | | 6534 | | this.source8 = source8; |
| | | 6535 | | this.source9 = source9; |
| | | 6536 | | this.source10 = source10; |
| | | 6537 | | this.source11 = source11; |
| | | 6538 | | this.source12 = source12; |
| | | 6539 | | |
| | | 6540 | | this.resultSelector = resultSelector; |
| | | 6541 | | } |
| | | 6542 | | |
| | | 6543 | | public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default) |
| | | 6544 | | { |
| | | 6545 | | return new _CombineLatest(source1, source2, source3, source4, source5, source6, source7, source8, source9, s |
| | | 6546 | | } |
| | | 6547 | | |
| | | 6548 | | class _CombineLatest : MoveNextSource, IUniTaskAsyncEnumerator<TResult> |
| | | 6549 | | { |
| | | 6550 | | static readonly Action<object> Completed1Delegate = Completed1; |
| | | 6551 | | static readonly Action<object> Completed2Delegate = Completed2; |
| | | 6552 | | static readonly Action<object> Completed3Delegate = Completed3; |
| | | 6553 | | static readonly Action<object> Completed4Delegate = Completed4; |
| | | 6554 | | static readonly Action<object> Completed5Delegate = Completed5; |
| | | 6555 | | static readonly Action<object> Completed6Delegate = Completed6; |
| | | 6556 | | static readonly Action<object> Completed7Delegate = Completed7; |
| | | 6557 | | static readonly Action<object> Completed8Delegate = Completed8; |
| | | 6558 | | static readonly Action<object> Completed9Delegate = Completed9; |
| | | 6559 | | static readonly Action<object> Completed10Delegate = Completed10; |
| | | 6560 | | static readonly Action<object> Completed11Delegate = Completed11; |
| | | 6561 | | static readonly Action<object> Completed12Delegate = Completed12; |
| | | 6562 | | const int CompleteCount = 12; |
| | | 6563 | | |
| | | 6564 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 6565 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 6566 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 6567 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 6568 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 6569 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 6570 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 6571 | | readonly IUniTaskAsyncEnumerable<T8> source8; |
| | | 6572 | | readonly IUniTaskAsyncEnumerable<T9> source9; |
| | | 6573 | | readonly IUniTaskAsyncEnumerable<T10> source10; |
| | | 6574 | | readonly IUniTaskAsyncEnumerable<T11> source11; |
| | | 6575 | | readonly IUniTaskAsyncEnumerable<T12> source12; |
| | | 6576 | | |
| | | 6577 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> resultSelector; |
| | | 6578 | | CancellationToken cancellationToken; |
| | | 6579 | | |
| | | 6580 | | IUniTaskAsyncEnumerator<T1> enumerator1; |
| | | 6581 | | UniTask<bool>.Awaiter awaiter1; |
| | | 6582 | | bool hasCurrent1; |
| | | 6583 | | bool running1; |
| | | 6584 | | T1 current1; |
| | | 6585 | | |
| | | 6586 | | IUniTaskAsyncEnumerator<T2> enumerator2; |
| | | 6587 | | UniTask<bool>.Awaiter awaiter2; |
| | | 6588 | | bool hasCurrent2; |
| | | 6589 | | bool running2; |
| | | 6590 | | T2 current2; |
| | | 6591 | | |
| | | 6592 | | IUniTaskAsyncEnumerator<T3> enumerator3; |
| | | 6593 | | UniTask<bool>.Awaiter awaiter3; |
| | | 6594 | | bool hasCurrent3; |
| | | 6595 | | bool running3; |
| | | 6596 | | T3 current3; |
| | | 6597 | | |
| | | 6598 | | IUniTaskAsyncEnumerator<T4> enumerator4; |
| | | 6599 | | UniTask<bool>.Awaiter awaiter4; |
| | | 6600 | | bool hasCurrent4; |
| | | 6601 | | bool running4; |
| | | 6602 | | T4 current4; |
| | | 6603 | | |
| | | 6604 | | IUniTaskAsyncEnumerator<T5> enumerator5; |
| | | 6605 | | UniTask<bool>.Awaiter awaiter5; |
| | | 6606 | | bool hasCurrent5; |
| | | 6607 | | bool running5; |
| | | 6608 | | T5 current5; |
| | | 6609 | | |
| | | 6610 | | IUniTaskAsyncEnumerator<T6> enumerator6; |
| | | 6611 | | UniTask<bool>.Awaiter awaiter6; |
| | | 6612 | | bool hasCurrent6; |
| | | 6613 | | bool running6; |
| | | 6614 | | T6 current6; |
| | | 6615 | | |
| | | 6616 | | IUniTaskAsyncEnumerator<T7> enumerator7; |
| | | 6617 | | UniTask<bool>.Awaiter awaiter7; |
| | | 6618 | | bool hasCurrent7; |
| | | 6619 | | bool running7; |
| | | 6620 | | T7 current7; |
| | | 6621 | | |
| | | 6622 | | IUniTaskAsyncEnumerator<T8> enumerator8; |
| | | 6623 | | UniTask<bool>.Awaiter awaiter8; |
| | | 6624 | | bool hasCurrent8; |
| | | 6625 | | bool running8; |
| | | 6626 | | T8 current8; |
| | | 6627 | | |
| | | 6628 | | IUniTaskAsyncEnumerator<T9> enumerator9; |
| | | 6629 | | UniTask<bool>.Awaiter awaiter9; |
| | | 6630 | | bool hasCurrent9; |
| | | 6631 | | bool running9; |
| | | 6632 | | T9 current9; |
| | | 6633 | | |
| | | 6634 | | IUniTaskAsyncEnumerator<T10> enumerator10; |
| | | 6635 | | UniTask<bool>.Awaiter awaiter10; |
| | | 6636 | | bool hasCurrent10; |
| | | 6637 | | bool running10; |
| | | 6638 | | T10 current10; |
| | | 6639 | | |
| | | 6640 | | IUniTaskAsyncEnumerator<T11> enumerator11; |
| | | 6641 | | UniTask<bool>.Awaiter awaiter11; |
| | | 6642 | | bool hasCurrent11; |
| | | 6643 | | bool running11; |
| | | 6644 | | T11 current11; |
| | | 6645 | | |
| | | 6646 | | IUniTaskAsyncEnumerator<T12> enumerator12; |
| | | 6647 | | UniTask<bool>.Awaiter awaiter12; |
| | | 6648 | | bool hasCurrent12; |
| | | 6649 | | bool running12; |
| | | 6650 | | T12 current12; |
| | | 6651 | | |
| | | 6652 | | int completedCount; |
| | | 6653 | | bool syncRunning; |
| | | 6654 | | TResult result; |
| | | 6655 | | |
| | | 6656 | | public _CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyn |
| | | 6657 | | { |
| | | 6658 | | this.source1 = source1; |
| | | 6659 | | this.source2 = source2; |
| | | 6660 | | this.source3 = source3; |
| | | 6661 | | this.source4 = source4; |
| | | 6662 | | this.source5 = source5; |
| | | 6663 | | this.source6 = source6; |
| | | 6664 | | this.source7 = source7; |
| | | 6665 | | this.source8 = source8; |
| | | 6666 | | this.source9 = source9; |
| | | 6667 | | this.source10 = source10; |
| | | 6668 | | this.source11 = source11; |
| | | 6669 | | this.source12 = source12; |
| | | 6670 | | |
| | | 6671 | | this.resultSelector = resultSelector; |
| | | 6672 | | this.cancellationToken = cancellationToken; |
| | | 6673 | | TaskTracker.TrackActiveTask(this, 3); |
| | | 6674 | | } |
| | | 6675 | | |
| | | 6676 | | public TResult Current => result; |
| | | 6677 | | |
| | | 6678 | | public UniTask<bool> MoveNextAsync() |
| | | 6679 | | { |
| | | 6680 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 6681 | | if (completedCount == CompleteCount) return CompletedTasks.False; |
| | | 6682 | | |
| | | 6683 | | if (enumerator1 == null) |
| | | 6684 | | { |
| | | 6685 | | enumerator1 = source1.GetAsyncEnumerator(cancellationToken); |
| | | 6686 | | enumerator2 = source2.GetAsyncEnumerator(cancellationToken); |
| | | 6687 | | enumerator3 = source3.GetAsyncEnumerator(cancellationToken); |
| | | 6688 | | enumerator4 = source4.GetAsyncEnumerator(cancellationToken); |
| | | 6689 | | enumerator5 = source5.GetAsyncEnumerator(cancellationToken); |
| | | 6690 | | enumerator6 = source6.GetAsyncEnumerator(cancellationToken); |
| | | 6691 | | enumerator7 = source7.GetAsyncEnumerator(cancellationToken); |
| | | 6692 | | enumerator8 = source8.GetAsyncEnumerator(cancellationToken); |
| | | 6693 | | enumerator9 = source9.GetAsyncEnumerator(cancellationToken); |
| | | 6694 | | enumerator10 = source10.GetAsyncEnumerator(cancellationToken); |
| | | 6695 | | enumerator11 = source11.GetAsyncEnumerator(cancellationToken); |
| | | 6696 | | enumerator12 = source12.GetAsyncEnumerator(cancellationToken); |
| | | 6697 | | } |
| | | 6698 | | |
| | | 6699 | | completionSource.Reset(); |
| | | 6700 | | |
| | | 6701 | | AGAIN: |
| | | 6702 | | syncRunning = true; |
| | | 6703 | | if (!running1) |
| | | 6704 | | { |
| | | 6705 | | running1 = true; |
| | | 6706 | | awaiter1 = enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 6707 | | if (awaiter1.IsCompleted) |
| | | 6708 | | { |
| | | 6709 | | Completed1(this); |
| | | 6710 | | } |
| | | 6711 | | else |
| | | 6712 | | { |
| | | 6713 | | awaiter1.SourceOnCompleted(Completed1Delegate, this); |
| | | 6714 | | } |
| | | 6715 | | } |
| | | 6716 | | if (!running2) |
| | | 6717 | | { |
| | | 6718 | | running2 = true; |
| | | 6719 | | awaiter2 = enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 6720 | | if (awaiter2.IsCompleted) |
| | | 6721 | | { |
| | | 6722 | | Completed2(this); |
| | | 6723 | | } |
| | | 6724 | | else |
| | | 6725 | | { |
| | | 6726 | | awaiter2.SourceOnCompleted(Completed2Delegate, this); |
| | | 6727 | | } |
| | | 6728 | | } |
| | | 6729 | | if (!running3) |
| | | 6730 | | { |
| | | 6731 | | running3 = true; |
| | | 6732 | | awaiter3 = enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 6733 | | if (awaiter3.IsCompleted) |
| | | 6734 | | { |
| | | 6735 | | Completed3(this); |
| | | 6736 | | } |
| | | 6737 | | else |
| | | 6738 | | { |
| | | 6739 | | awaiter3.SourceOnCompleted(Completed3Delegate, this); |
| | | 6740 | | } |
| | | 6741 | | } |
| | | 6742 | | if (!running4) |
| | | 6743 | | { |
| | | 6744 | | running4 = true; |
| | | 6745 | | awaiter4 = enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 6746 | | if (awaiter4.IsCompleted) |
| | | 6747 | | { |
| | | 6748 | | Completed4(this); |
| | | 6749 | | } |
| | | 6750 | | else |
| | | 6751 | | { |
| | | 6752 | | awaiter4.SourceOnCompleted(Completed4Delegate, this); |
| | | 6753 | | } |
| | | 6754 | | } |
| | | 6755 | | if (!running5) |
| | | 6756 | | { |
| | | 6757 | | running5 = true; |
| | | 6758 | | awaiter5 = enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 6759 | | if (awaiter5.IsCompleted) |
| | | 6760 | | { |
| | | 6761 | | Completed5(this); |
| | | 6762 | | } |
| | | 6763 | | else |
| | | 6764 | | { |
| | | 6765 | | awaiter5.SourceOnCompleted(Completed5Delegate, this); |
| | | 6766 | | } |
| | | 6767 | | } |
| | | 6768 | | if (!running6) |
| | | 6769 | | { |
| | | 6770 | | running6 = true; |
| | | 6771 | | awaiter6 = enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 6772 | | if (awaiter6.IsCompleted) |
| | | 6773 | | { |
| | | 6774 | | Completed6(this); |
| | | 6775 | | } |
| | | 6776 | | else |
| | | 6777 | | { |
| | | 6778 | | awaiter6.SourceOnCompleted(Completed6Delegate, this); |
| | | 6779 | | } |
| | | 6780 | | } |
| | | 6781 | | if (!running7) |
| | | 6782 | | { |
| | | 6783 | | running7 = true; |
| | | 6784 | | awaiter7 = enumerator7.MoveNextAsync().GetAwaiter(); |
| | | 6785 | | if (awaiter7.IsCompleted) |
| | | 6786 | | { |
| | | 6787 | | Completed7(this); |
| | | 6788 | | } |
| | | 6789 | | else |
| | | 6790 | | { |
| | | 6791 | | awaiter7.SourceOnCompleted(Completed7Delegate, this); |
| | | 6792 | | } |
| | | 6793 | | } |
| | | 6794 | | if (!running8) |
| | | 6795 | | { |
| | | 6796 | | running8 = true; |
| | | 6797 | | awaiter8 = enumerator8.MoveNextAsync().GetAwaiter(); |
| | | 6798 | | if (awaiter8.IsCompleted) |
| | | 6799 | | { |
| | | 6800 | | Completed8(this); |
| | | 6801 | | } |
| | | 6802 | | else |
| | | 6803 | | { |
| | | 6804 | | awaiter8.SourceOnCompleted(Completed8Delegate, this); |
| | | 6805 | | } |
| | | 6806 | | } |
| | | 6807 | | if (!running9) |
| | | 6808 | | { |
| | | 6809 | | running9 = true; |
| | | 6810 | | awaiter9 = enumerator9.MoveNextAsync().GetAwaiter(); |
| | | 6811 | | if (awaiter9.IsCompleted) |
| | | 6812 | | { |
| | | 6813 | | Completed9(this); |
| | | 6814 | | } |
| | | 6815 | | else |
| | | 6816 | | { |
| | | 6817 | | awaiter9.SourceOnCompleted(Completed9Delegate, this); |
| | | 6818 | | } |
| | | 6819 | | } |
| | | 6820 | | if (!running10) |
| | | 6821 | | { |
| | | 6822 | | running10 = true; |
| | | 6823 | | awaiter10 = enumerator10.MoveNextAsync().GetAwaiter(); |
| | | 6824 | | if (awaiter10.IsCompleted) |
| | | 6825 | | { |
| | | 6826 | | Completed10(this); |
| | | 6827 | | } |
| | | 6828 | | else |
| | | 6829 | | { |
| | | 6830 | | awaiter10.SourceOnCompleted(Completed10Delegate, this); |
| | | 6831 | | } |
| | | 6832 | | } |
| | | 6833 | | if (!running11) |
| | | 6834 | | { |
| | | 6835 | | running11 = true; |
| | | 6836 | | awaiter11 = enumerator11.MoveNextAsync().GetAwaiter(); |
| | | 6837 | | if (awaiter11.IsCompleted) |
| | | 6838 | | { |
| | | 6839 | | Completed11(this); |
| | | 6840 | | } |
| | | 6841 | | else |
| | | 6842 | | { |
| | | 6843 | | awaiter11.SourceOnCompleted(Completed11Delegate, this); |
| | | 6844 | | } |
| | | 6845 | | } |
| | | 6846 | | if (!running12) |
| | | 6847 | | { |
| | | 6848 | | running12 = true; |
| | | 6849 | | awaiter12 = enumerator12.MoveNextAsync().GetAwaiter(); |
| | | 6850 | | if (awaiter12.IsCompleted) |
| | | 6851 | | { |
| | | 6852 | | Completed12(this); |
| | | 6853 | | } |
| | | 6854 | | else |
| | | 6855 | | { |
| | | 6856 | | awaiter12.SourceOnCompleted(Completed12Delegate, this); |
| | | 6857 | | } |
| | | 6858 | | } |
| | | 6859 | | |
| | | 6860 | | if (!running1 || !running2 || !running3 || !running4 || !running5 || !running6 || !running7 || !running8 |
| | | 6861 | | { |
| | | 6862 | | goto AGAIN; |
| | | 6863 | | } |
| | | 6864 | | syncRunning = false; |
| | | 6865 | | |
| | | 6866 | | return new UniTask<bool>(this, completionSource.Version); |
| | | 6867 | | } |
| | | 6868 | | |
| | | 6869 | | static void Completed1(object state) |
| | | 6870 | | { |
| | | 6871 | | var self = (_CombineLatest)state; |
| | | 6872 | | self.running1 = false; |
| | | 6873 | | |
| | | 6874 | | try |
| | | 6875 | | { |
| | | 6876 | | if (self.awaiter1.GetResult()) |
| | | 6877 | | { |
| | | 6878 | | self.hasCurrent1 = true; |
| | | 6879 | | self.current1 = self.enumerator1.Current; |
| | | 6880 | | goto SUCCESS; |
| | | 6881 | | } |
| | | 6882 | | else |
| | | 6883 | | { |
| | | 6884 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 6885 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 6886 | | { |
| | | 6887 | | goto COMPLETE; |
| | | 6888 | | } |
| | | 6889 | | return; |
| | | 6890 | | } |
| | | 6891 | | } |
| | | 6892 | | catch (Exception ex) |
| | | 6893 | | { |
| | | 6894 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 6895 | | self.completedCount = CompleteCount; |
| | | 6896 | | self.completionSource.TrySetException(ex); |
| | | 6897 | | return; |
| | | 6898 | | } |
| | | 6899 | | |
| | | 6900 | | SUCCESS: |
| | | 6901 | | if (!self.TrySetResult()) |
| | | 6902 | | { |
| | | 6903 | | if (self.syncRunning) return; |
| | | 6904 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 6905 | | try |
| | | 6906 | | { |
| | | 6907 | | self.awaiter1 = self.enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 6908 | | } |
| | | 6909 | | catch (Exception ex) |
| | | 6910 | | { |
| | | 6911 | | self.completedCount = CompleteCount; |
| | | 6912 | | self.completionSource.TrySetException(ex); |
| | | 6913 | | return; |
| | | 6914 | | } |
| | | 6915 | | |
| | | 6916 | | self.awaiter1.SourceOnCompleted(Completed1Delegate, self); |
| | | 6917 | | } |
| | | 6918 | | return; |
| | | 6919 | | COMPLETE: |
| | | 6920 | | self.completionSource.TrySetResult(false); |
| | | 6921 | | return; |
| | | 6922 | | } |
| | | 6923 | | |
| | | 6924 | | static void Completed2(object state) |
| | | 6925 | | { |
| | | 6926 | | var self = (_CombineLatest)state; |
| | | 6927 | | self.running2 = false; |
| | | 6928 | | |
| | | 6929 | | try |
| | | 6930 | | { |
| | | 6931 | | if (self.awaiter2.GetResult()) |
| | | 6932 | | { |
| | | 6933 | | self.hasCurrent2 = true; |
| | | 6934 | | self.current2 = self.enumerator2.Current; |
| | | 6935 | | goto SUCCESS; |
| | | 6936 | | } |
| | | 6937 | | else |
| | | 6938 | | { |
| | | 6939 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 6940 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 6941 | | { |
| | | 6942 | | goto COMPLETE; |
| | | 6943 | | } |
| | | 6944 | | return; |
| | | 6945 | | } |
| | | 6946 | | } |
| | | 6947 | | catch (Exception ex) |
| | | 6948 | | { |
| | | 6949 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 6950 | | self.completedCount = CompleteCount; |
| | | 6951 | | self.completionSource.TrySetException(ex); |
| | | 6952 | | return; |
| | | 6953 | | } |
| | | 6954 | | |
| | | 6955 | | SUCCESS: |
| | | 6956 | | if (!self.TrySetResult()) |
| | | 6957 | | { |
| | | 6958 | | if (self.syncRunning) return; |
| | | 6959 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 6960 | | try |
| | | 6961 | | { |
| | | 6962 | | self.awaiter2 = self.enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 6963 | | } |
| | | 6964 | | catch (Exception ex) |
| | | 6965 | | { |
| | | 6966 | | self.completedCount = CompleteCount; |
| | | 6967 | | self.completionSource.TrySetException(ex); |
| | | 6968 | | return; |
| | | 6969 | | } |
| | | 6970 | | |
| | | 6971 | | self.awaiter2.SourceOnCompleted(Completed2Delegate, self); |
| | | 6972 | | } |
| | | 6973 | | return; |
| | | 6974 | | COMPLETE: |
| | | 6975 | | self.completionSource.TrySetResult(false); |
| | | 6976 | | return; |
| | | 6977 | | } |
| | | 6978 | | |
| | | 6979 | | static void Completed3(object state) |
| | | 6980 | | { |
| | | 6981 | | var self = (_CombineLatest)state; |
| | | 6982 | | self.running3 = false; |
| | | 6983 | | |
| | | 6984 | | try |
| | | 6985 | | { |
| | | 6986 | | if (self.awaiter3.GetResult()) |
| | | 6987 | | { |
| | | 6988 | | self.hasCurrent3 = true; |
| | | 6989 | | self.current3 = self.enumerator3.Current; |
| | | 6990 | | goto SUCCESS; |
| | | 6991 | | } |
| | | 6992 | | else |
| | | 6993 | | { |
| | | 6994 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 6995 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 6996 | | { |
| | | 6997 | | goto COMPLETE; |
| | | 6998 | | } |
| | | 6999 | | return; |
| | | 7000 | | } |
| | | 7001 | | } |
| | | 7002 | | catch (Exception ex) |
| | | 7003 | | { |
| | | 7004 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 7005 | | self.completedCount = CompleteCount; |
| | | 7006 | | self.completionSource.TrySetException(ex); |
| | | 7007 | | return; |
| | | 7008 | | } |
| | | 7009 | | |
| | | 7010 | | SUCCESS: |
| | | 7011 | | if (!self.TrySetResult()) |
| | | 7012 | | { |
| | | 7013 | | if (self.syncRunning) return; |
| | | 7014 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 7015 | | try |
| | | 7016 | | { |
| | | 7017 | | self.awaiter3 = self.enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 7018 | | } |
| | | 7019 | | catch (Exception ex) |
| | | 7020 | | { |
| | | 7021 | | self.completedCount = CompleteCount; |
| | | 7022 | | self.completionSource.TrySetException(ex); |
| | | 7023 | | return; |
| | | 7024 | | } |
| | | 7025 | | |
| | | 7026 | | self.awaiter3.SourceOnCompleted(Completed3Delegate, self); |
| | | 7027 | | } |
| | | 7028 | | return; |
| | | 7029 | | COMPLETE: |
| | | 7030 | | self.completionSource.TrySetResult(false); |
| | | 7031 | | return; |
| | | 7032 | | } |
| | | 7033 | | |
| | | 7034 | | static void Completed4(object state) |
| | | 7035 | | { |
| | | 7036 | | var self = (_CombineLatest)state; |
| | | 7037 | | self.running4 = false; |
| | | 7038 | | |
| | | 7039 | | try |
| | | 7040 | | { |
| | | 7041 | | if (self.awaiter4.GetResult()) |
| | | 7042 | | { |
| | | 7043 | | self.hasCurrent4 = true; |
| | | 7044 | | self.current4 = self.enumerator4.Current; |
| | | 7045 | | goto SUCCESS; |
| | | 7046 | | } |
| | | 7047 | | else |
| | | 7048 | | { |
| | | 7049 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 7050 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 7051 | | { |
| | | 7052 | | goto COMPLETE; |
| | | 7053 | | } |
| | | 7054 | | return; |
| | | 7055 | | } |
| | | 7056 | | } |
| | | 7057 | | catch (Exception ex) |
| | | 7058 | | { |
| | | 7059 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 7060 | | self.completedCount = CompleteCount; |
| | | 7061 | | self.completionSource.TrySetException(ex); |
| | | 7062 | | return; |
| | | 7063 | | } |
| | | 7064 | | |
| | | 7065 | | SUCCESS: |
| | | 7066 | | if (!self.TrySetResult()) |
| | | 7067 | | { |
| | | 7068 | | if (self.syncRunning) return; |
| | | 7069 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 7070 | | try |
| | | 7071 | | { |
| | | 7072 | | self.awaiter4 = self.enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 7073 | | } |
| | | 7074 | | catch (Exception ex) |
| | | 7075 | | { |
| | | 7076 | | self.completedCount = CompleteCount; |
| | | 7077 | | self.completionSource.TrySetException(ex); |
| | | 7078 | | return; |
| | | 7079 | | } |
| | | 7080 | | |
| | | 7081 | | self.awaiter4.SourceOnCompleted(Completed4Delegate, self); |
| | | 7082 | | } |
| | | 7083 | | return; |
| | | 7084 | | COMPLETE: |
| | | 7085 | | self.completionSource.TrySetResult(false); |
| | | 7086 | | return; |
| | | 7087 | | } |
| | | 7088 | | |
| | | 7089 | | static void Completed5(object state) |
| | | 7090 | | { |
| | | 7091 | | var self = (_CombineLatest)state; |
| | | 7092 | | self.running5 = false; |
| | | 7093 | | |
| | | 7094 | | try |
| | | 7095 | | { |
| | | 7096 | | if (self.awaiter5.GetResult()) |
| | | 7097 | | { |
| | | 7098 | | self.hasCurrent5 = true; |
| | | 7099 | | self.current5 = self.enumerator5.Current; |
| | | 7100 | | goto SUCCESS; |
| | | 7101 | | } |
| | | 7102 | | else |
| | | 7103 | | { |
| | | 7104 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 7105 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 7106 | | { |
| | | 7107 | | goto COMPLETE; |
| | | 7108 | | } |
| | | 7109 | | return; |
| | | 7110 | | } |
| | | 7111 | | } |
| | | 7112 | | catch (Exception ex) |
| | | 7113 | | { |
| | | 7114 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 7115 | | self.completedCount = CompleteCount; |
| | | 7116 | | self.completionSource.TrySetException(ex); |
| | | 7117 | | return; |
| | | 7118 | | } |
| | | 7119 | | |
| | | 7120 | | SUCCESS: |
| | | 7121 | | if (!self.TrySetResult()) |
| | | 7122 | | { |
| | | 7123 | | if (self.syncRunning) return; |
| | | 7124 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 7125 | | try |
| | | 7126 | | { |
| | | 7127 | | self.awaiter5 = self.enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 7128 | | } |
| | | 7129 | | catch (Exception ex) |
| | | 7130 | | { |
| | | 7131 | | self.completedCount = CompleteCount; |
| | | 7132 | | self.completionSource.TrySetException(ex); |
| | | 7133 | | return; |
| | | 7134 | | } |
| | | 7135 | | |
| | | 7136 | | self.awaiter5.SourceOnCompleted(Completed5Delegate, self); |
| | | 7137 | | } |
| | | 7138 | | return; |
| | | 7139 | | COMPLETE: |
| | | 7140 | | self.completionSource.TrySetResult(false); |
| | | 7141 | | return; |
| | | 7142 | | } |
| | | 7143 | | |
| | | 7144 | | static void Completed6(object state) |
| | | 7145 | | { |
| | | 7146 | | var self = (_CombineLatest)state; |
| | | 7147 | | self.running6 = false; |
| | | 7148 | | |
| | | 7149 | | try |
| | | 7150 | | { |
| | | 7151 | | if (self.awaiter6.GetResult()) |
| | | 7152 | | { |
| | | 7153 | | self.hasCurrent6 = true; |
| | | 7154 | | self.current6 = self.enumerator6.Current; |
| | | 7155 | | goto SUCCESS; |
| | | 7156 | | } |
| | | 7157 | | else |
| | | 7158 | | { |
| | | 7159 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 7160 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 7161 | | { |
| | | 7162 | | goto COMPLETE; |
| | | 7163 | | } |
| | | 7164 | | return; |
| | | 7165 | | } |
| | | 7166 | | } |
| | | 7167 | | catch (Exception ex) |
| | | 7168 | | { |
| | | 7169 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 7170 | | self.completedCount = CompleteCount; |
| | | 7171 | | self.completionSource.TrySetException(ex); |
| | | 7172 | | return; |
| | | 7173 | | } |
| | | 7174 | | |
| | | 7175 | | SUCCESS: |
| | | 7176 | | if (!self.TrySetResult()) |
| | | 7177 | | { |
| | | 7178 | | if (self.syncRunning) return; |
| | | 7179 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 7180 | | try |
| | | 7181 | | { |
| | | 7182 | | self.awaiter6 = self.enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 7183 | | } |
| | | 7184 | | catch (Exception ex) |
| | | 7185 | | { |
| | | 7186 | | self.completedCount = CompleteCount; |
| | | 7187 | | self.completionSource.TrySetException(ex); |
| | | 7188 | | return; |
| | | 7189 | | } |
| | | 7190 | | |
| | | 7191 | | self.awaiter6.SourceOnCompleted(Completed6Delegate, self); |
| | | 7192 | | } |
| | | 7193 | | return; |
| | | 7194 | | COMPLETE: |
| | | 7195 | | self.completionSource.TrySetResult(false); |
| | | 7196 | | return; |
| | | 7197 | | } |
| | | 7198 | | |
| | | 7199 | | static void Completed7(object state) |
| | | 7200 | | { |
| | | 7201 | | var self = (_CombineLatest)state; |
| | | 7202 | | self.running7 = false; |
| | | 7203 | | |
| | | 7204 | | try |
| | | 7205 | | { |
| | | 7206 | | if (self.awaiter7.GetResult()) |
| | | 7207 | | { |
| | | 7208 | | self.hasCurrent7 = true; |
| | | 7209 | | self.current7 = self.enumerator7.Current; |
| | | 7210 | | goto SUCCESS; |
| | | 7211 | | } |
| | | 7212 | | else |
| | | 7213 | | { |
| | | 7214 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 7215 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 7216 | | { |
| | | 7217 | | goto COMPLETE; |
| | | 7218 | | } |
| | | 7219 | | return; |
| | | 7220 | | } |
| | | 7221 | | } |
| | | 7222 | | catch (Exception ex) |
| | | 7223 | | { |
| | | 7224 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 7225 | | self.completedCount = CompleteCount; |
| | | 7226 | | self.completionSource.TrySetException(ex); |
| | | 7227 | | return; |
| | | 7228 | | } |
| | | 7229 | | |
| | | 7230 | | SUCCESS: |
| | | 7231 | | if (!self.TrySetResult()) |
| | | 7232 | | { |
| | | 7233 | | if (self.syncRunning) return; |
| | | 7234 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 7235 | | try |
| | | 7236 | | { |
| | | 7237 | | self.awaiter7 = self.enumerator7.MoveNextAsync().GetAwaiter(); |
| | | 7238 | | } |
| | | 7239 | | catch (Exception ex) |
| | | 7240 | | { |
| | | 7241 | | self.completedCount = CompleteCount; |
| | | 7242 | | self.completionSource.TrySetException(ex); |
| | | 7243 | | return; |
| | | 7244 | | } |
| | | 7245 | | |
| | | 7246 | | self.awaiter7.SourceOnCompleted(Completed7Delegate, self); |
| | | 7247 | | } |
| | | 7248 | | return; |
| | | 7249 | | COMPLETE: |
| | | 7250 | | self.completionSource.TrySetResult(false); |
| | | 7251 | | return; |
| | | 7252 | | } |
| | | 7253 | | |
| | | 7254 | | static void Completed8(object state) |
| | | 7255 | | { |
| | | 7256 | | var self = (_CombineLatest)state; |
| | | 7257 | | self.running8 = false; |
| | | 7258 | | |
| | | 7259 | | try |
| | | 7260 | | { |
| | | 7261 | | if (self.awaiter8.GetResult()) |
| | | 7262 | | { |
| | | 7263 | | self.hasCurrent8 = true; |
| | | 7264 | | self.current8 = self.enumerator8.Current; |
| | | 7265 | | goto SUCCESS; |
| | | 7266 | | } |
| | | 7267 | | else |
| | | 7268 | | { |
| | | 7269 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 7270 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 7271 | | { |
| | | 7272 | | goto COMPLETE; |
| | | 7273 | | } |
| | | 7274 | | return; |
| | | 7275 | | } |
| | | 7276 | | } |
| | | 7277 | | catch (Exception ex) |
| | | 7278 | | { |
| | | 7279 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 7280 | | self.completedCount = CompleteCount; |
| | | 7281 | | self.completionSource.TrySetException(ex); |
| | | 7282 | | return; |
| | | 7283 | | } |
| | | 7284 | | |
| | | 7285 | | SUCCESS: |
| | | 7286 | | if (!self.TrySetResult()) |
| | | 7287 | | { |
| | | 7288 | | if (self.syncRunning) return; |
| | | 7289 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 7290 | | try |
| | | 7291 | | { |
| | | 7292 | | self.awaiter8 = self.enumerator8.MoveNextAsync().GetAwaiter(); |
| | | 7293 | | } |
| | | 7294 | | catch (Exception ex) |
| | | 7295 | | { |
| | | 7296 | | self.completedCount = CompleteCount; |
| | | 7297 | | self.completionSource.TrySetException(ex); |
| | | 7298 | | return; |
| | | 7299 | | } |
| | | 7300 | | |
| | | 7301 | | self.awaiter8.SourceOnCompleted(Completed8Delegate, self); |
| | | 7302 | | } |
| | | 7303 | | return; |
| | | 7304 | | COMPLETE: |
| | | 7305 | | self.completionSource.TrySetResult(false); |
| | | 7306 | | return; |
| | | 7307 | | } |
| | | 7308 | | |
| | | 7309 | | static void Completed9(object state) |
| | | 7310 | | { |
| | | 7311 | | var self = (_CombineLatest)state; |
| | | 7312 | | self.running9 = false; |
| | | 7313 | | |
| | | 7314 | | try |
| | | 7315 | | { |
| | | 7316 | | if (self.awaiter9.GetResult()) |
| | | 7317 | | { |
| | | 7318 | | self.hasCurrent9 = true; |
| | | 7319 | | self.current9 = self.enumerator9.Current; |
| | | 7320 | | goto SUCCESS; |
| | | 7321 | | } |
| | | 7322 | | else |
| | | 7323 | | { |
| | | 7324 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 7325 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 7326 | | { |
| | | 7327 | | goto COMPLETE; |
| | | 7328 | | } |
| | | 7329 | | return; |
| | | 7330 | | } |
| | | 7331 | | } |
| | | 7332 | | catch (Exception ex) |
| | | 7333 | | { |
| | | 7334 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 7335 | | self.completedCount = CompleteCount; |
| | | 7336 | | self.completionSource.TrySetException(ex); |
| | | 7337 | | return; |
| | | 7338 | | } |
| | | 7339 | | |
| | | 7340 | | SUCCESS: |
| | | 7341 | | if (!self.TrySetResult()) |
| | | 7342 | | { |
| | | 7343 | | if (self.syncRunning) return; |
| | | 7344 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 7345 | | try |
| | | 7346 | | { |
| | | 7347 | | self.awaiter9 = self.enumerator9.MoveNextAsync().GetAwaiter(); |
| | | 7348 | | } |
| | | 7349 | | catch (Exception ex) |
| | | 7350 | | { |
| | | 7351 | | self.completedCount = CompleteCount; |
| | | 7352 | | self.completionSource.TrySetException(ex); |
| | | 7353 | | return; |
| | | 7354 | | } |
| | | 7355 | | |
| | | 7356 | | self.awaiter9.SourceOnCompleted(Completed9Delegate, self); |
| | | 7357 | | } |
| | | 7358 | | return; |
| | | 7359 | | COMPLETE: |
| | | 7360 | | self.completionSource.TrySetResult(false); |
| | | 7361 | | return; |
| | | 7362 | | } |
| | | 7363 | | |
| | | 7364 | | static void Completed10(object state) |
| | | 7365 | | { |
| | | 7366 | | var self = (_CombineLatest)state; |
| | | 7367 | | self.running10 = false; |
| | | 7368 | | |
| | | 7369 | | try |
| | | 7370 | | { |
| | | 7371 | | if (self.awaiter10.GetResult()) |
| | | 7372 | | { |
| | | 7373 | | self.hasCurrent10 = true; |
| | | 7374 | | self.current10 = self.enumerator10.Current; |
| | | 7375 | | goto SUCCESS; |
| | | 7376 | | } |
| | | 7377 | | else |
| | | 7378 | | { |
| | | 7379 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | | 7380 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 7381 | | { |
| | | 7382 | | goto COMPLETE; |
| | | 7383 | | } |
| | | 7384 | | return; |
| | | 7385 | | } |
| | | 7386 | | } |
| | | 7387 | | catch (Exception ex) |
| | | 7388 | | { |
| | | 7389 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | | 7390 | | self.completedCount = CompleteCount; |
| | | 7391 | | self.completionSource.TrySetException(ex); |
| | | 7392 | | return; |
| | | 7393 | | } |
| | | 7394 | | |
| | | 7395 | | SUCCESS: |
| | | 7396 | | if (!self.TrySetResult()) |
| | | 7397 | | { |
| | | 7398 | | if (self.syncRunning) return; |
| | | 7399 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | | 7400 | | try |
| | | 7401 | | { |
| | | 7402 | | self.awaiter10 = self.enumerator10.MoveNextAsync().GetAwaiter(); |
| | | 7403 | | } |
| | | 7404 | | catch (Exception ex) |
| | | 7405 | | { |
| | | 7406 | | self.completedCount = CompleteCount; |
| | | 7407 | | self.completionSource.TrySetException(ex); |
| | | 7408 | | return; |
| | | 7409 | | } |
| | | 7410 | | |
| | | 7411 | | self.awaiter10.SourceOnCompleted(Completed10Delegate, self); |
| | | 7412 | | } |
| | | 7413 | | return; |
| | | 7414 | | COMPLETE: |
| | | 7415 | | self.completionSource.TrySetResult(false); |
| | | 7416 | | return; |
| | | 7417 | | } |
| | | 7418 | | |
| | | 7419 | | static void Completed11(object state) |
| | | 7420 | | { |
| | | 7421 | | var self = (_CombineLatest)state; |
| | | 7422 | | self.running11 = false; |
| | | 7423 | | |
| | | 7424 | | try |
| | | 7425 | | { |
| | | 7426 | | if (self.awaiter11.GetResult()) |
| | | 7427 | | { |
| | | 7428 | | self.hasCurrent11 = true; |
| | | 7429 | | self.current11 = self.enumerator11.Current; |
| | | 7430 | | goto SUCCESS; |
| | | 7431 | | } |
| | | 7432 | | else |
| | | 7433 | | { |
| | | 7434 | | self.running11 = true; // as complete, no more call MoveNextAsync. |
| | | 7435 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 7436 | | { |
| | | 7437 | | goto COMPLETE; |
| | | 7438 | | } |
| | | 7439 | | return; |
| | | 7440 | | } |
| | | 7441 | | } |
| | | 7442 | | catch (Exception ex) |
| | | 7443 | | { |
| | | 7444 | | self.running11 = true; // as complete, no more call MoveNextAsync. |
| | | 7445 | | self.completedCount = CompleteCount; |
| | | 7446 | | self.completionSource.TrySetException(ex); |
| | | 7447 | | return; |
| | | 7448 | | } |
| | | 7449 | | |
| | | 7450 | | SUCCESS: |
| | | 7451 | | if (!self.TrySetResult()) |
| | | 7452 | | { |
| | | 7453 | | if (self.syncRunning) return; |
| | | 7454 | | self.running11 = true; // as complete, no more call MoveNextAsync. |
| | | 7455 | | try |
| | | 7456 | | { |
| | | 7457 | | self.awaiter11 = self.enumerator11.MoveNextAsync().GetAwaiter(); |
| | | 7458 | | } |
| | | 7459 | | catch (Exception ex) |
| | | 7460 | | { |
| | | 7461 | | self.completedCount = CompleteCount; |
| | | 7462 | | self.completionSource.TrySetException(ex); |
| | | 7463 | | return; |
| | | 7464 | | } |
| | | 7465 | | |
| | | 7466 | | self.awaiter11.SourceOnCompleted(Completed11Delegate, self); |
| | | 7467 | | } |
| | | 7468 | | return; |
| | | 7469 | | COMPLETE: |
| | | 7470 | | self.completionSource.TrySetResult(false); |
| | | 7471 | | return; |
| | | 7472 | | } |
| | | 7473 | | |
| | | 7474 | | static void Completed12(object state) |
| | | 7475 | | { |
| | | 7476 | | var self = (_CombineLatest)state; |
| | | 7477 | | self.running12 = false; |
| | | 7478 | | |
| | | 7479 | | try |
| | | 7480 | | { |
| | | 7481 | | if (self.awaiter12.GetResult()) |
| | | 7482 | | { |
| | | 7483 | | self.hasCurrent12 = true; |
| | | 7484 | | self.current12 = self.enumerator12.Current; |
| | | 7485 | | goto SUCCESS; |
| | | 7486 | | } |
| | | 7487 | | else |
| | | 7488 | | { |
| | | 7489 | | self.running12 = true; // as complete, no more call MoveNextAsync. |
| | | 7490 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 7491 | | { |
| | | 7492 | | goto COMPLETE; |
| | | 7493 | | } |
| | | 7494 | | return; |
| | | 7495 | | } |
| | | 7496 | | } |
| | | 7497 | | catch (Exception ex) |
| | | 7498 | | { |
| | | 7499 | | self.running12 = true; // as complete, no more call MoveNextAsync. |
| | | 7500 | | self.completedCount = CompleteCount; |
| | | 7501 | | self.completionSource.TrySetException(ex); |
| | | 7502 | | return; |
| | | 7503 | | } |
| | | 7504 | | |
| | | 7505 | | SUCCESS: |
| | | 7506 | | if (!self.TrySetResult()) |
| | | 7507 | | { |
| | | 7508 | | if (self.syncRunning) return; |
| | | 7509 | | self.running12 = true; // as complete, no more call MoveNextAsync. |
| | | 7510 | | try |
| | | 7511 | | { |
| | | 7512 | | self.awaiter12 = self.enumerator12.MoveNextAsync().GetAwaiter(); |
| | | 7513 | | } |
| | | 7514 | | catch (Exception ex) |
| | | 7515 | | { |
| | | 7516 | | self.completedCount = CompleteCount; |
| | | 7517 | | self.completionSource.TrySetException(ex); |
| | | 7518 | | return; |
| | | 7519 | | } |
| | | 7520 | | |
| | | 7521 | | self.awaiter12.SourceOnCompleted(Completed12Delegate, self); |
| | | 7522 | | } |
| | | 7523 | | return; |
| | | 7524 | | COMPLETE: |
| | | 7525 | | self.completionSource.TrySetResult(false); |
| | | 7526 | | return; |
| | | 7527 | | } |
| | | 7528 | | |
| | | 7529 | | bool TrySetResult() |
| | | 7530 | | { |
| | | 7531 | | if (hasCurrent1 && hasCurrent2 && hasCurrent3 && hasCurrent4 && hasCurrent5 && hasCurrent6 && hasCurrent |
| | | 7532 | | { |
| | | 7533 | | result = resultSelector(current1, current2, current3, current4, current5, current6, current7, curren |
| | | 7534 | | completionSource.TrySetResult(true); |
| | | 7535 | | return true; |
| | | 7536 | | } |
| | | 7537 | | else |
| | | 7538 | | { |
| | | 7539 | | return false; |
| | | 7540 | | } |
| | | 7541 | | } |
| | | 7542 | | |
| | | 7543 | | public async UniTask DisposeAsync() |
| | | 7544 | | { |
| | | 7545 | | TaskTracker.RemoveTracking(this); |
| | | 7546 | | if (enumerator1 != null) |
| | | 7547 | | { |
| | | 7548 | | await enumerator1.DisposeAsync(); |
| | | 7549 | | } |
| | | 7550 | | if (enumerator2 != null) |
| | | 7551 | | { |
| | | 7552 | | await enumerator2.DisposeAsync(); |
| | | 7553 | | } |
| | | 7554 | | if (enumerator3 != null) |
| | | 7555 | | { |
| | | 7556 | | await enumerator3.DisposeAsync(); |
| | | 7557 | | } |
| | | 7558 | | if (enumerator4 != null) |
| | | 7559 | | { |
| | | 7560 | | await enumerator4.DisposeAsync(); |
| | | 7561 | | } |
| | | 7562 | | if (enumerator5 != null) |
| | | 7563 | | { |
| | | 7564 | | await enumerator5.DisposeAsync(); |
| | | 7565 | | } |
| | | 7566 | | if (enumerator6 != null) |
| | | 7567 | | { |
| | | 7568 | | await enumerator6.DisposeAsync(); |
| | | 7569 | | } |
| | | 7570 | | if (enumerator7 != null) |
| | | 7571 | | { |
| | | 7572 | | await enumerator7.DisposeAsync(); |
| | | 7573 | | } |
| | | 7574 | | if (enumerator8 != null) |
| | | 7575 | | { |
| | | 7576 | | await enumerator8.DisposeAsync(); |
| | | 7577 | | } |
| | | 7578 | | if (enumerator9 != null) |
| | | 7579 | | { |
| | | 7580 | | await enumerator9.DisposeAsync(); |
| | | 7581 | | } |
| | | 7582 | | if (enumerator10 != null) |
| | | 7583 | | { |
| | | 7584 | | await enumerator10.DisposeAsync(); |
| | | 7585 | | } |
| | | 7586 | | if (enumerator11 != null) |
| | | 7587 | | { |
| | | 7588 | | await enumerator11.DisposeAsync(); |
| | | 7589 | | } |
| | | 7590 | | if (enumerator12 != null) |
| | | 7591 | | { |
| | | 7592 | | await enumerator12.DisposeAsync(); |
| | | 7593 | | } |
| | | 7594 | | } |
| | | 7595 | | } |
| | | 7596 | | } |
| | | 7597 | | |
| | | 7598 | | internal class CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult> : IUniTaskAsyncEnumera |
| | | 7599 | | { |
| | | 7600 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 7601 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 7602 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 7603 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 7604 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 7605 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 7606 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 7607 | | readonly IUniTaskAsyncEnumerable<T8> source8; |
| | | 7608 | | readonly IUniTaskAsyncEnumerable<T9> source9; |
| | | 7609 | | readonly IUniTaskAsyncEnumerable<T10> source10; |
| | | 7610 | | readonly IUniTaskAsyncEnumerable<T11> source11; |
| | | 7611 | | readonly IUniTaskAsyncEnumerable<T12> source12; |
| | | 7612 | | readonly IUniTaskAsyncEnumerable<T13> source13; |
| | | 7613 | | |
| | | 7614 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult> resultSelector; |
| | | 7615 | | |
| | | 7616 | | public CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyncEnum |
| | | 7617 | | { |
| | | 7618 | | this.source1 = source1; |
| | | 7619 | | this.source2 = source2; |
| | | 7620 | | this.source3 = source3; |
| | | 7621 | | this.source4 = source4; |
| | | 7622 | | this.source5 = source5; |
| | | 7623 | | this.source6 = source6; |
| | | 7624 | | this.source7 = source7; |
| | | 7625 | | this.source8 = source8; |
| | | 7626 | | this.source9 = source9; |
| | | 7627 | | this.source10 = source10; |
| | | 7628 | | this.source11 = source11; |
| | | 7629 | | this.source12 = source12; |
| | | 7630 | | this.source13 = source13; |
| | | 7631 | | |
| | | 7632 | | this.resultSelector = resultSelector; |
| | | 7633 | | } |
| | | 7634 | | |
| | | 7635 | | public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default) |
| | | 7636 | | { |
| | | 7637 | | return new _CombineLatest(source1, source2, source3, source4, source5, source6, source7, source8, source9, s |
| | | 7638 | | } |
| | | 7639 | | |
| | | 7640 | | class _CombineLatest : MoveNextSource, IUniTaskAsyncEnumerator<TResult> |
| | | 7641 | | { |
| | | 7642 | | static readonly Action<object> Completed1Delegate = Completed1; |
| | | 7643 | | static readonly Action<object> Completed2Delegate = Completed2; |
| | | 7644 | | static readonly Action<object> Completed3Delegate = Completed3; |
| | | 7645 | | static readonly Action<object> Completed4Delegate = Completed4; |
| | | 7646 | | static readonly Action<object> Completed5Delegate = Completed5; |
| | | 7647 | | static readonly Action<object> Completed6Delegate = Completed6; |
| | | 7648 | | static readonly Action<object> Completed7Delegate = Completed7; |
| | | 7649 | | static readonly Action<object> Completed8Delegate = Completed8; |
| | | 7650 | | static readonly Action<object> Completed9Delegate = Completed9; |
| | | 7651 | | static readonly Action<object> Completed10Delegate = Completed10; |
| | | 7652 | | static readonly Action<object> Completed11Delegate = Completed11; |
| | | 7653 | | static readonly Action<object> Completed12Delegate = Completed12; |
| | | 7654 | | static readonly Action<object> Completed13Delegate = Completed13; |
| | | 7655 | | const int CompleteCount = 13; |
| | | 7656 | | |
| | | 7657 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 7658 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 7659 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 7660 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 7661 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 7662 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 7663 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 7664 | | readonly IUniTaskAsyncEnumerable<T8> source8; |
| | | 7665 | | readonly IUniTaskAsyncEnumerable<T9> source9; |
| | | 7666 | | readonly IUniTaskAsyncEnumerable<T10> source10; |
| | | 7667 | | readonly IUniTaskAsyncEnumerable<T11> source11; |
| | | 7668 | | readonly IUniTaskAsyncEnumerable<T12> source12; |
| | | 7669 | | readonly IUniTaskAsyncEnumerable<T13> source13; |
| | | 7670 | | |
| | | 7671 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult> resultSelector; |
| | | 7672 | | CancellationToken cancellationToken; |
| | | 7673 | | |
| | | 7674 | | IUniTaskAsyncEnumerator<T1> enumerator1; |
| | | 7675 | | UniTask<bool>.Awaiter awaiter1; |
| | | 7676 | | bool hasCurrent1; |
| | | 7677 | | bool running1; |
| | | 7678 | | T1 current1; |
| | | 7679 | | |
| | | 7680 | | IUniTaskAsyncEnumerator<T2> enumerator2; |
| | | 7681 | | UniTask<bool>.Awaiter awaiter2; |
| | | 7682 | | bool hasCurrent2; |
| | | 7683 | | bool running2; |
| | | 7684 | | T2 current2; |
| | | 7685 | | |
| | | 7686 | | IUniTaskAsyncEnumerator<T3> enumerator3; |
| | | 7687 | | UniTask<bool>.Awaiter awaiter3; |
| | | 7688 | | bool hasCurrent3; |
| | | 7689 | | bool running3; |
| | | 7690 | | T3 current3; |
| | | 7691 | | |
| | | 7692 | | IUniTaskAsyncEnumerator<T4> enumerator4; |
| | | 7693 | | UniTask<bool>.Awaiter awaiter4; |
| | | 7694 | | bool hasCurrent4; |
| | | 7695 | | bool running4; |
| | | 7696 | | T4 current4; |
| | | 7697 | | |
| | | 7698 | | IUniTaskAsyncEnumerator<T5> enumerator5; |
| | | 7699 | | UniTask<bool>.Awaiter awaiter5; |
| | | 7700 | | bool hasCurrent5; |
| | | 7701 | | bool running5; |
| | | 7702 | | T5 current5; |
| | | 7703 | | |
| | | 7704 | | IUniTaskAsyncEnumerator<T6> enumerator6; |
| | | 7705 | | UniTask<bool>.Awaiter awaiter6; |
| | | 7706 | | bool hasCurrent6; |
| | | 7707 | | bool running6; |
| | | 7708 | | T6 current6; |
| | | 7709 | | |
| | | 7710 | | IUniTaskAsyncEnumerator<T7> enumerator7; |
| | | 7711 | | UniTask<bool>.Awaiter awaiter7; |
| | | 7712 | | bool hasCurrent7; |
| | | 7713 | | bool running7; |
| | | 7714 | | T7 current7; |
| | | 7715 | | |
| | | 7716 | | IUniTaskAsyncEnumerator<T8> enumerator8; |
| | | 7717 | | UniTask<bool>.Awaiter awaiter8; |
| | | 7718 | | bool hasCurrent8; |
| | | 7719 | | bool running8; |
| | | 7720 | | T8 current8; |
| | | 7721 | | |
| | | 7722 | | IUniTaskAsyncEnumerator<T9> enumerator9; |
| | | 7723 | | UniTask<bool>.Awaiter awaiter9; |
| | | 7724 | | bool hasCurrent9; |
| | | 7725 | | bool running9; |
| | | 7726 | | T9 current9; |
| | | 7727 | | |
| | | 7728 | | IUniTaskAsyncEnumerator<T10> enumerator10; |
| | | 7729 | | UniTask<bool>.Awaiter awaiter10; |
| | | 7730 | | bool hasCurrent10; |
| | | 7731 | | bool running10; |
| | | 7732 | | T10 current10; |
| | | 7733 | | |
| | | 7734 | | IUniTaskAsyncEnumerator<T11> enumerator11; |
| | | 7735 | | UniTask<bool>.Awaiter awaiter11; |
| | | 7736 | | bool hasCurrent11; |
| | | 7737 | | bool running11; |
| | | 7738 | | T11 current11; |
| | | 7739 | | |
| | | 7740 | | IUniTaskAsyncEnumerator<T12> enumerator12; |
| | | 7741 | | UniTask<bool>.Awaiter awaiter12; |
| | | 7742 | | bool hasCurrent12; |
| | | 7743 | | bool running12; |
| | | 7744 | | T12 current12; |
| | | 7745 | | |
| | | 7746 | | IUniTaskAsyncEnumerator<T13> enumerator13; |
| | | 7747 | | UniTask<bool>.Awaiter awaiter13; |
| | | 7748 | | bool hasCurrent13; |
| | | 7749 | | bool running13; |
| | | 7750 | | T13 current13; |
| | | 7751 | | |
| | | 7752 | | int completedCount; |
| | | 7753 | | bool syncRunning; |
| | | 7754 | | TResult result; |
| | | 7755 | | |
| | | 7756 | | public _CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyn |
| | | 7757 | | { |
| | | 7758 | | this.source1 = source1; |
| | | 7759 | | this.source2 = source2; |
| | | 7760 | | this.source3 = source3; |
| | | 7761 | | this.source4 = source4; |
| | | 7762 | | this.source5 = source5; |
| | | 7763 | | this.source6 = source6; |
| | | 7764 | | this.source7 = source7; |
| | | 7765 | | this.source8 = source8; |
| | | 7766 | | this.source9 = source9; |
| | | 7767 | | this.source10 = source10; |
| | | 7768 | | this.source11 = source11; |
| | | 7769 | | this.source12 = source12; |
| | | 7770 | | this.source13 = source13; |
| | | 7771 | | |
| | | 7772 | | this.resultSelector = resultSelector; |
| | | 7773 | | this.cancellationToken = cancellationToken; |
| | | 7774 | | TaskTracker.TrackActiveTask(this, 3); |
| | | 7775 | | } |
| | | 7776 | | |
| | | 7777 | | public TResult Current => result; |
| | | 7778 | | |
| | | 7779 | | public UniTask<bool> MoveNextAsync() |
| | | 7780 | | { |
| | | 7781 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 7782 | | if (completedCount == CompleteCount) return CompletedTasks.False; |
| | | 7783 | | |
| | | 7784 | | if (enumerator1 == null) |
| | | 7785 | | { |
| | | 7786 | | enumerator1 = source1.GetAsyncEnumerator(cancellationToken); |
| | | 7787 | | enumerator2 = source2.GetAsyncEnumerator(cancellationToken); |
| | | 7788 | | enumerator3 = source3.GetAsyncEnumerator(cancellationToken); |
| | | 7789 | | enumerator4 = source4.GetAsyncEnumerator(cancellationToken); |
| | | 7790 | | enumerator5 = source5.GetAsyncEnumerator(cancellationToken); |
| | | 7791 | | enumerator6 = source6.GetAsyncEnumerator(cancellationToken); |
| | | 7792 | | enumerator7 = source7.GetAsyncEnumerator(cancellationToken); |
| | | 7793 | | enumerator8 = source8.GetAsyncEnumerator(cancellationToken); |
| | | 7794 | | enumerator9 = source9.GetAsyncEnumerator(cancellationToken); |
| | | 7795 | | enumerator10 = source10.GetAsyncEnumerator(cancellationToken); |
| | | 7796 | | enumerator11 = source11.GetAsyncEnumerator(cancellationToken); |
| | | 7797 | | enumerator12 = source12.GetAsyncEnumerator(cancellationToken); |
| | | 7798 | | enumerator13 = source13.GetAsyncEnumerator(cancellationToken); |
| | | 7799 | | } |
| | | 7800 | | |
| | | 7801 | | completionSource.Reset(); |
| | | 7802 | | |
| | | 7803 | | AGAIN: |
| | | 7804 | | syncRunning = true; |
| | | 7805 | | if (!running1) |
| | | 7806 | | { |
| | | 7807 | | running1 = true; |
| | | 7808 | | awaiter1 = enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 7809 | | if (awaiter1.IsCompleted) |
| | | 7810 | | { |
| | | 7811 | | Completed1(this); |
| | | 7812 | | } |
| | | 7813 | | else |
| | | 7814 | | { |
| | | 7815 | | awaiter1.SourceOnCompleted(Completed1Delegate, this); |
| | | 7816 | | } |
| | | 7817 | | } |
| | | 7818 | | if (!running2) |
| | | 7819 | | { |
| | | 7820 | | running2 = true; |
| | | 7821 | | awaiter2 = enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 7822 | | if (awaiter2.IsCompleted) |
| | | 7823 | | { |
| | | 7824 | | Completed2(this); |
| | | 7825 | | } |
| | | 7826 | | else |
| | | 7827 | | { |
| | | 7828 | | awaiter2.SourceOnCompleted(Completed2Delegate, this); |
| | | 7829 | | } |
| | | 7830 | | } |
| | | 7831 | | if (!running3) |
| | | 7832 | | { |
| | | 7833 | | running3 = true; |
| | | 7834 | | awaiter3 = enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 7835 | | if (awaiter3.IsCompleted) |
| | | 7836 | | { |
| | | 7837 | | Completed3(this); |
| | | 7838 | | } |
| | | 7839 | | else |
| | | 7840 | | { |
| | | 7841 | | awaiter3.SourceOnCompleted(Completed3Delegate, this); |
| | | 7842 | | } |
| | | 7843 | | } |
| | | 7844 | | if (!running4) |
| | | 7845 | | { |
| | | 7846 | | running4 = true; |
| | | 7847 | | awaiter4 = enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 7848 | | if (awaiter4.IsCompleted) |
| | | 7849 | | { |
| | | 7850 | | Completed4(this); |
| | | 7851 | | } |
| | | 7852 | | else |
| | | 7853 | | { |
| | | 7854 | | awaiter4.SourceOnCompleted(Completed4Delegate, this); |
| | | 7855 | | } |
| | | 7856 | | } |
| | | 7857 | | if (!running5) |
| | | 7858 | | { |
| | | 7859 | | running5 = true; |
| | | 7860 | | awaiter5 = enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 7861 | | if (awaiter5.IsCompleted) |
| | | 7862 | | { |
| | | 7863 | | Completed5(this); |
| | | 7864 | | } |
| | | 7865 | | else |
| | | 7866 | | { |
| | | 7867 | | awaiter5.SourceOnCompleted(Completed5Delegate, this); |
| | | 7868 | | } |
| | | 7869 | | } |
| | | 7870 | | if (!running6) |
| | | 7871 | | { |
| | | 7872 | | running6 = true; |
| | | 7873 | | awaiter6 = enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 7874 | | if (awaiter6.IsCompleted) |
| | | 7875 | | { |
| | | 7876 | | Completed6(this); |
| | | 7877 | | } |
| | | 7878 | | else |
| | | 7879 | | { |
| | | 7880 | | awaiter6.SourceOnCompleted(Completed6Delegate, this); |
| | | 7881 | | } |
| | | 7882 | | } |
| | | 7883 | | if (!running7) |
| | | 7884 | | { |
| | | 7885 | | running7 = true; |
| | | 7886 | | awaiter7 = enumerator7.MoveNextAsync().GetAwaiter(); |
| | | 7887 | | if (awaiter7.IsCompleted) |
| | | 7888 | | { |
| | | 7889 | | Completed7(this); |
| | | 7890 | | } |
| | | 7891 | | else |
| | | 7892 | | { |
| | | 7893 | | awaiter7.SourceOnCompleted(Completed7Delegate, this); |
| | | 7894 | | } |
| | | 7895 | | } |
| | | 7896 | | if (!running8) |
| | | 7897 | | { |
| | | 7898 | | running8 = true; |
| | | 7899 | | awaiter8 = enumerator8.MoveNextAsync().GetAwaiter(); |
| | | 7900 | | if (awaiter8.IsCompleted) |
| | | 7901 | | { |
| | | 7902 | | Completed8(this); |
| | | 7903 | | } |
| | | 7904 | | else |
| | | 7905 | | { |
| | | 7906 | | awaiter8.SourceOnCompleted(Completed8Delegate, this); |
| | | 7907 | | } |
| | | 7908 | | } |
| | | 7909 | | if (!running9) |
| | | 7910 | | { |
| | | 7911 | | running9 = true; |
| | | 7912 | | awaiter9 = enumerator9.MoveNextAsync().GetAwaiter(); |
| | | 7913 | | if (awaiter9.IsCompleted) |
| | | 7914 | | { |
| | | 7915 | | Completed9(this); |
| | | 7916 | | } |
| | | 7917 | | else |
| | | 7918 | | { |
| | | 7919 | | awaiter9.SourceOnCompleted(Completed9Delegate, this); |
| | | 7920 | | } |
| | | 7921 | | } |
| | | 7922 | | if (!running10) |
| | | 7923 | | { |
| | | 7924 | | running10 = true; |
| | | 7925 | | awaiter10 = enumerator10.MoveNextAsync().GetAwaiter(); |
| | | 7926 | | if (awaiter10.IsCompleted) |
| | | 7927 | | { |
| | | 7928 | | Completed10(this); |
| | | 7929 | | } |
| | | 7930 | | else |
| | | 7931 | | { |
| | | 7932 | | awaiter10.SourceOnCompleted(Completed10Delegate, this); |
| | | 7933 | | } |
| | | 7934 | | } |
| | | 7935 | | if (!running11) |
| | | 7936 | | { |
| | | 7937 | | running11 = true; |
| | | 7938 | | awaiter11 = enumerator11.MoveNextAsync().GetAwaiter(); |
| | | 7939 | | if (awaiter11.IsCompleted) |
| | | 7940 | | { |
| | | 7941 | | Completed11(this); |
| | | 7942 | | } |
| | | 7943 | | else |
| | | 7944 | | { |
| | | 7945 | | awaiter11.SourceOnCompleted(Completed11Delegate, this); |
| | | 7946 | | } |
| | | 7947 | | } |
| | | 7948 | | if (!running12) |
| | | 7949 | | { |
| | | 7950 | | running12 = true; |
| | | 7951 | | awaiter12 = enumerator12.MoveNextAsync().GetAwaiter(); |
| | | 7952 | | if (awaiter12.IsCompleted) |
| | | 7953 | | { |
| | | 7954 | | Completed12(this); |
| | | 7955 | | } |
| | | 7956 | | else |
| | | 7957 | | { |
| | | 7958 | | awaiter12.SourceOnCompleted(Completed12Delegate, this); |
| | | 7959 | | } |
| | | 7960 | | } |
| | | 7961 | | if (!running13) |
| | | 7962 | | { |
| | | 7963 | | running13 = true; |
| | | 7964 | | awaiter13 = enumerator13.MoveNextAsync().GetAwaiter(); |
| | | 7965 | | if (awaiter13.IsCompleted) |
| | | 7966 | | { |
| | | 7967 | | Completed13(this); |
| | | 7968 | | } |
| | | 7969 | | else |
| | | 7970 | | { |
| | | 7971 | | awaiter13.SourceOnCompleted(Completed13Delegate, this); |
| | | 7972 | | } |
| | | 7973 | | } |
| | | 7974 | | |
| | | 7975 | | if (!running1 || !running2 || !running3 || !running4 || !running5 || !running6 || !running7 || !running8 |
| | | 7976 | | { |
| | | 7977 | | goto AGAIN; |
| | | 7978 | | } |
| | | 7979 | | syncRunning = false; |
| | | 7980 | | |
| | | 7981 | | return new UniTask<bool>(this, completionSource.Version); |
| | | 7982 | | } |
| | | 7983 | | |
| | | 7984 | | static void Completed1(object state) |
| | | 7985 | | { |
| | | 7986 | | var self = (_CombineLatest)state; |
| | | 7987 | | self.running1 = false; |
| | | 7988 | | |
| | | 7989 | | try |
| | | 7990 | | { |
| | | 7991 | | if (self.awaiter1.GetResult()) |
| | | 7992 | | { |
| | | 7993 | | self.hasCurrent1 = true; |
| | | 7994 | | self.current1 = self.enumerator1.Current; |
| | | 7995 | | goto SUCCESS; |
| | | 7996 | | } |
| | | 7997 | | else |
| | | 7998 | | { |
| | | 7999 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 8000 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 8001 | | { |
| | | 8002 | | goto COMPLETE; |
| | | 8003 | | } |
| | | 8004 | | return; |
| | | 8005 | | } |
| | | 8006 | | } |
| | | 8007 | | catch (Exception ex) |
| | | 8008 | | { |
| | | 8009 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 8010 | | self.completedCount = CompleteCount; |
| | | 8011 | | self.completionSource.TrySetException(ex); |
| | | 8012 | | return; |
| | | 8013 | | } |
| | | 8014 | | |
| | | 8015 | | SUCCESS: |
| | | 8016 | | if (!self.TrySetResult()) |
| | | 8017 | | { |
| | | 8018 | | if (self.syncRunning) return; |
| | | 8019 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 8020 | | try |
| | | 8021 | | { |
| | | 8022 | | self.awaiter1 = self.enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 8023 | | } |
| | | 8024 | | catch (Exception ex) |
| | | 8025 | | { |
| | | 8026 | | self.completedCount = CompleteCount; |
| | | 8027 | | self.completionSource.TrySetException(ex); |
| | | 8028 | | return; |
| | | 8029 | | } |
| | | 8030 | | |
| | | 8031 | | self.awaiter1.SourceOnCompleted(Completed1Delegate, self); |
| | | 8032 | | } |
| | | 8033 | | return; |
| | | 8034 | | COMPLETE: |
| | | 8035 | | self.completionSource.TrySetResult(false); |
| | | 8036 | | return; |
| | | 8037 | | } |
| | | 8038 | | |
| | | 8039 | | static void Completed2(object state) |
| | | 8040 | | { |
| | | 8041 | | var self = (_CombineLatest)state; |
| | | 8042 | | self.running2 = false; |
| | | 8043 | | |
| | | 8044 | | try |
| | | 8045 | | { |
| | | 8046 | | if (self.awaiter2.GetResult()) |
| | | 8047 | | { |
| | | 8048 | | self.hasCurrent2 = true; |
| | | 8049 | | self.current2 = self.enumerator2.Current; |
| | | 8050 | | goto SUCCESS; |
| | | 8051 | | } |
| | | 8052 | | else |
| | | 8053 | | { |
| | | 8054 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 8055 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 8056 | | { |
| | | 8057 | | goto COMPLETE; |
| | | 8058 | | } |
| | | 8059 | | return; |
| | | 8060 | | } |
| | | 8061 | | } |
| | | 8062 | | catch (Exception ex) |
| | | 8063 | | { |
| | | 8064 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 8065 | | self.completedCount = CompleteCount; |
| | | 8066 | | self.completionSource.TrySetException(ex); |
| | | 8067 | | return; |
| | | 8068 | | } |
| | | 8069 | | |
| | | 8070 | | SUCCESS: |
| | | 8071 | | if (!self.TrySetResult()) |
| | | 8072 | | { |
| | | 8073 | | if (self.syncRunning) return; |
| | | 8074 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 8075 | | try |
| | | 8076 | | { |
| | | 8077 | | self.awaiter2 = self.enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 8078 | | } |
| | | 8079 | | catch (Exception ex) |
| | | 8080 | | { |
| | | 8081 | | self.completedCount = CompleteCount; |
| | | 8082 | | self.completionSource.TrySetException(ex); |
| | | 8083 | | return; |
| | | 8084 | | } |
| | | 8085 | | |
| | | 8086 | | self.awaiter2.SourceOnCompleted(Completed2Delegate, self); |
| | | 8087 | | } |
| | | 8088 | | return; |
| | | 8089 | | COMPLETE: |
| | | 8090 | | self.completionSource.TrySetResult(false); |
| | | 8091 | | return; |
| | | 8092 | | } |
| | | 8093 | | |
| | | 8094 | | static void Completed3(object state) |
| | | 8095 | | { |
| | | 8096 | | var self = (_CombineLatest)state; |
| | | 8097 | | self.running3 = false; |
| | | 8098 | | |
| | | 8099 | | try |
| | | 8100 | | { |
| | | 8101 | | if (self.awaiter3.GetResult()) |
| | | 8102 | | { |
| | | 8103 | | self.hasCurrent3 = true; |
| | | 8104 | | self.current3 = self.enumerator3.Current; |
| | | 8105 | | goto SUCCESS; |
| | | 8106 | | } |
| | | 8107 | | else |
| | | 8108 | | { |
| | | 8109 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 8110 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 8111 | | { |
| | | 8112 | | goto COMPLETE; |
| | | 8113 | | } |
| | | 8114 | | return; |
| | | 8115 | | } |
| | | 8116 | | } |
| | | 8117 | | catch (Exception ex) |
| | | 8118 | | { |
| | | 8119 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 8120 | | self.completedCount = CompleteCount; |
| | | 8121 | | self.completionSource.TrySetException(ex); |
| | | 8122 | | return; |
| | | 8123 | | } |
| | | 8124 | | |
| | | 8125 | | SUCCESS: |
| | | 8126 | | if (!self.TrySetResult()) |
| | | 8127 | | { |
| | | 8128 | | if (self.syncRunning) return; |
| | | 8129 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 8130 | | try |
| | | 8131 | | { |
| | | 8132 | | self.awaiter3 = self.enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 8133 | | } |
| | | 8134 | | catch (Exception ex) |
| | | 8135 | | { |
| | | 8136 | | self.completedCount = CompleteCount; |
| | | 8137 | | self.completionSource.TrySetException(ex); |
| | | 8138 | | return; |
| | | 8139 | | } |
| | | 8140 | | |
| | | 8141 | | self.awaiter3.SourceOnCompleted(Completed3Delegate, self); |
| | | 8142 | | } |
| | | 8143 | | return; |
| | | 8144 | | COMPLETE: |
| | | 8145 | | self.completionSource.TrySetResult(false); |
| | | 8146 | | return; |
| | | 8147 | | } |
| | | 8148 | | |
| | | 8149 | | static void Completed4(object state) |
| | | 8150 | | { |
| | | 8151 | | var self = (_CombineLatest)state; |
| | | 8152 | | self.running4 = false; |
| | | 8153 | | |
| | | 8154 | | try |
| | | 8155 | | { |
| | | 8156 | | if (self.awaiter4.GetResult()) |
| | | 8157 | | { |
| | | 8158 | | self.hasCurrent4 = true; |
| | | 8159 | | self.current4 = self.enumerator4.Current; |
| | | 8160 | | goto SUCCESS; |
| | | 8161 | | } |
| | | 8162 | | else |
| | | 8163 | | { |
| | | 8164 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 8165 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 8166 | | { |
| | | 8167 | | goto COMPLETE; |
| | | 8168 | | } |
| | | 8169 | | return; |
| | | 8170 | | } |
| | | 8171 | | } |
| | | 8172 | | catch (Exception ex) |
| | | 8173 | | { |
| | | 8174 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 8175 | | self.completedCount = CompleteCount; |
| | | 8176 | | self.completionSource.TrySetException(ex); |
| | | 8177 | | return; |
| | | 8178 | | } |
| | | 8179 | | |
| | | 8180 | | SUCCESS: |
| | | 8181 | | if (!self.TrySetResult()) |
| | | 8182 | | { |
| | | 8183 | | if (self.syncRunning) return; |
| | | 8184 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 8185 | | try |
| | | 8186 | | { |
| | | 8187 | | self.awaiter4 = self.enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 8188 | | } |
| | | 8189 | | catch (Exception ex) |
| | | 8190 | | { |
| | | 8191 | | self.completedCount = CompleteCount; |
| | | 8192 | | self.completionSource.TrySetException(ex); |
| | | 8193 | | return; |
| | | 8194 | | } |
| | | 8195 | | |
| | | 8196 | | self.awaiter4.SourceOnCompleted(Completed4Delegate, self); |
| | | 8197 | | } |
| | | 8198 | | return; |
| | | 8199 | | COMPLETE: |
| | | 8200 | | self.completionSource.TrySetResult(false); |
| | | 8201 | | return; |
| | | 8202 | | } |
| | | 8203 | | |
| | | 8204 | | static void Completed5(object state) |
| | | 8205 | | { |
| | | 8206 | | var self = (_CombineLatest)state; |
| | | 8207 | | self.running5 = false; |
| | | 8208 | | |
| | | 8209 | | try |
| | | 8210 | | { |
| | | 8211 | | if (self.awaiter5.GetResult()) |
| | | 8212 | | { |
| | | 8213 | | self.hasCurrent5 = true; |
| | | 8214 | | self.current5 = self.enumerator5.Current; |
| | | 8215 | | goto SUCCESS; |
| | | 8216 | | } |
| | | 8217 | | else |
| | | 8218 | | { |
| | | 8219 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 8220 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 8221 | | { |
| | | 8222 | | goto COMPLETE; |
| | | 8223 | | } |
| | | 8224 | | return; |
| | | 8225 | | } |
| | | 8226 | | } |
| | | 8227 | | catch (Exception ex) |
| | | 8228 | | { |
| | | 8229 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 8230 | | self.completedCount = CompleteCount; |
| | | 8231 | | self.completionSource.TrySetException(ex); |
| | | 8232 | | return; |
| | | 8233 | | } |
| | | 8234 | | |
| | | 8235 | | SUCCESS: |
| | | 8236 | | if (!self.TrySetResult()) |
| | | 8237 | | { |
| | | 8238 | | if (self.syncRunning) return; |
| | | 8239 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 8240 | | try |
| | | 8241 | | { |
| | | 8242 | | self.awaiter5 = self.enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 8243 | | } |
| | | 8244 | | catch (Exception ex) |
| | | 8245 | | { |
| | | 8246 | | self.completedCount = CompleteCount; |
| | | 8247 | | self.completionSource.TrySetException(ex); |
| | | 8248 | | return; |
| | | 8249 | | } |
| | | 8250 | | |
| | | 8251 | | self.awaiter5.SourceOnCompleted(Completed5Delegate, self); |
| | | 8252 | | } |
| | | 8253 | | return; |
| | | 8254 | | COMPLETE: |
| | | 8255 | | self.completionSource.TrySetResult(false); |
| | | 8256 | | return; |
| | | 8257 | | } |
| | | 8258 | | |
| | | 8259 | | static void Completed6(object state) |
| | | 8260 | | { |
| | | 8261 | | var self = (_CombineLatest)state; |
| | | 8262 | | self.running6 = false; |
| | | 8263 | | |
| | | 8264 | | try |
| | | 8265 | | { |
| | | 8266 | | if (self.awaiter6.GetResult()) |
| | | 8267 | | { |
| | | 8268 | | self.hasCurrent6 = true; |
| | | 8269 | | self.current6 = self.enumerator6.Current; |
| | | 8270 | | goto SUCCESS; |
| | | 8271 | | } |
| | | 8272 | | else |
| | | 8273 | | { |
| | | 8274 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 8275 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 8276 | | { |
| | | 8277 | | goto COMPLETE; |
| | | 8278 | | } |
| | | 8279 | | return; |
| | | 8280 | | } |
| | | 8281 | | } |
| | | 8282 | | catch (Exception ex) |
| | | 8283 | | { |
| | | 8284 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 8285 | | self.completedCount = CompleteCount; |
| | | 8286 | | self.completionSource.TrySetException(ex); |
| | | 8287 | | return; |
| | | 8288 | | } |
| | | 8289 | | |
| | | 8290 | | SUCCESS: |
| | | 8291 | | if (!self.TrySetResult()) |
| | | 8292 | | { |
| | | 8293 | | if (self.syncRunning) return; |
| | | 8294 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 8295 | | try |
| | | 8296 | | { |
| | | 8297 | | self.awaiter6 = self.enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 8298 | | } |
| | | 8299 | | catch (Exception ex) |
| | | 8300 | | { |
| | | 8301 | | self.completedCount = CompleteCount; |
| | | 8302 | | self.completionSource.TrySetException(ex); |
| | | 8303 | | return; |
| | | 8304 | | } |
| | | 8305 | | |
| | | 8306 | | self.awaiter6.SourceOnCompleted(Completed6Delegate, self); |
| | | 8307 | | } |
| | | 8308 | | return; |
| | | 8309 | | COMPLETE: |
| | | 8310 | | self.completionSource.TrySetResult(false); |
| | | 8311 | | return; |
| | | 8312 | | } |
| | | 8313 | | |
| | | 8314 | | static void Completed7(object state) |
| | | 8315 | | { |
| | | 8316 | | var self = (_CombineLatest)state; |
| | | 8317 | | self.running7 = false; |
| | | 8318 | | |
| | | 8319 | | try |
| | | 8320 | | { |
| | | 8321 | | if (self.awaiter7.GetResult()) |
| | | 8322 | | { |
| | | 8323 | | self.hasCurrent7 = true; |
| | | 8324 | | self.current7 = self.enumerator7.Current; |
| | | 8325 | | goto SUCCESS; |
| | | 8326 | | } |
| | | 8327 | | else |
| | | 8328 | | { |
| | | 8329 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 8330 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 8331 | | { |
| | | 8332 | | goto COMPLETE; |
| | | 8333 | | } |
| | | 8334 | | return; |
| | | 8335 | | } |
| | | 8336 | | } |
| | | 8337 | | catch (Exception ex) |
| | | 8338 | | { |
| | | 8339 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 8340 | | self.completedCount = CompleteCount; |
| | | 8341 | | self.completionSource.TrySetException(ex); |
| | | 8342 | | return; |
| | | 8343 | | } |
| | | 8344 | | |
| | | 8345 | | SUCCESS: |
| | | 8346 | | if (!self.TrySetResult()) |
| | | 8347 | | { |
| | | 8348 | | if (self.syncRunning) return; |
| | | 8349 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 8350 | | try |
| | | 8351 | | { |
| | | 8352 | | self.awaiter7 = self.enumerator7.MoveNextAsync().GetAwaiter(); |
| | | 8353 | | } |
| | | 8354 | | catch (Exception ex) |
| | | 8355 | | { |
| | | 8356 | | self.completedCount = CompleteCount; |
| | | 8357 | | self.completionSource.TrySetException(ex); |
| | | 8358 | | return; |
| | | 8359 | | } |
| | | 8360 | | |
| | | 8361 | | self.awaiter7.SourceOnCompleted(Completed7Delegate, self); |
| | | 8362 | | } |
| | | 8363 | | return; |
| | | 8364 | | COMPLETE: |
| | | 8365 | | self.completionSource.TrySetResult(false); |
| | | 8366 | | return; |
| | | 8367 | | } |
| | | 8368 | | |
| | | 8369 | | static void Completed8(object state) |
| | | 8370 | | { |
| | | 8371 | | var self = (_CombineLatest)state; |
| | | 8372 | | self.running8 = false; |
| | | 8373 | | |
| | | 8374 | | try |
| | | 8375 | | { |
| | | 8376 | | if (self.awaiter8.GetResult()) |
| | | 8377 | | { |
| | | 8378 | | self.hasCurrent8 = true; |
| | | 8379 | | self.current8 = self.enumerator8.Current; |
| | | 8380 | | goto SUCCESS; |
| | | 8381 | | } |
| | | 8382 | | else |
| | | 8383 | | { |
| | | 8384 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 8385 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 8386 | | { |
| | | 8387 | | goto COMPLETE; |
| | | 8388 | | } |
| | | 8389 | | return; |
| | | 8390 | | } |
| | | 8391 | | } |
| | | 8392 | | catch (Exception ex) |
| | | 8393 | | { |
| | | 8394 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 8395 | | self.completedCount = CompleteCount; |
| | | 8396 | | self.completionSource.TrySetException(ex); |
| | | 8397 | | return; |
| | | 8398 | | } |
| | | 8399 | | |
| | | 8400 | | SUCCESS: |
| | | 8401 | | if (!self.TrySetResult()) |
| | | 8402 | | { |
| | | 8403 | | if (self.syncRunning) return; |
| | | 8404 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 8405 | | try |
| | | 8406 | | { |
| | | 8407 | | self.awaiter8 = self.enumerator8.MoveNextAsync().GetAwaiter(); |
| | | 8408 | | } |
| | | 8409 | | catch (Exception ex) |
| | | 8410 | | { |
| | | 8411 | | self.completedCount = CompleteCount; |
| | | 8412 | | self.completionSource.TrySetException(ex); |
| | | 8413 | | return; |
| | | 8414 | | } |
| | | 8415 | | |
| | | 8416 | | self.awaiter8.SourceOnCompleted(Completed8Delegate, self); |
| | | 8417 | | } |
| | | 8418 | | return; |
| | | 8419 | | COMPLETE: |
| | | 8420 | | self.completionSource.TrySetResult(false); |
| | | 8421 | | return; |
| | | 8422 | | } |
| | | 8423 | | |
| | | 8424 | | static void Completed9(object state) |
| | | 8425 | | { |
| | | 8426 | | var self = (_CombineLatest)state; |
| | | 8427 | | self.running9 = false; |
| | | 8428 | | |
| | | 8429 | | try |
| | | 8430 | | { |
| | | 8431 | | if (self.awaiter9.GetResult()) |
| | | 8432 | | { |
| | | 8433 | | self.hasCurrent9 = true; |
| | | 8434 | | self.current9 = self.enumerator9.Current; |
| | | 8435 | | goto SUCCESS; |
| | | 8436 | | } |
| | | 8437 | | else |
| | | 8438 | | { |
| | | 8439 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 8440 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 8441 | | { |
| | | 8442 | | goto COMPLETE; |
| | | 8443 | | } |
| | | 8444 | | return; |
| | | 8445 | | } |
| | | 8446 | | } |
| | | 8447 | | catch (Exception ex) |
| | | 8448 | | { |
| | | 8449 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 8450 | | self.completedCount = CompleteCount; |
| | | 8451 | | self.completionSource.TrySetException(ex); |
| | | 8452 | | return; |
| | | 8453 | | } |
| | | 8454 | | |
| | | 8455 | | SUCCESS: |
| | | 8456 | | if (!self.TrySetResult()) |
| | | 8457 | | { |
| | | 8458 | | if (self.syncRunning) return; |
| | | 8459 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 8460 | | try |
| | | 8461 | | { |
| | | 8462 | | self.awaiter9 = self.enumerator9.MoveNextAsync().GetAwaiter(); |
| | | 8463 | | } |
| | | 8464 | | catch (Exception ex) |
| | | 8465 | | { |
| | | 8466 | | self.completedCount = CompleteCount; |
| | | 8467 | | self.completionSource.TrySetException(ex); |
| | | 8468 | | return; |
| | | 8469 | | } |
| | | 8470 | | |
| | | 8471 | | self.awaiter9.SourceOnCompleted(Completed9Delegate, self); |
| | | 8472 | | } |
| | | 8473 | | return; |
| | | 8474 | | COMPLETE: |
| | | 8475 | | self.completionSource.TrySetResult(false); |
| | | 8476 | | return; |
| | | 8477 | | } |
| | | 8478 | | |
| | | 8479 | | static void Completed10(object state) |
| | | 8480 | | { |
| | | 8481 | | var self = (_CombineLatest)state; |
| | | 8482 | | self.running10 = false; |
| | | 8483 | | |
| | | 8484 | | try |
| | | 8485 | | { |
| | | 8486 | | if (self.awaiter10.GetResult()) |
| | | 8487 | | { |
| | | 8488 | | self.hasCurrent10 = true; |
| | | 8489 | | self.current10 = self.enumerator10.Current; |
| | | 8490 | | goto SUCCESS; |
| | | 8491 | | } |
| | | 8492 | | else |
| | | 8493 | | { |
| | | 8494 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | | 8495 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 8496 | | { |
| | | 8497 | | goto COMPLETE; |
| | | 8498 | | } |
| | | 8499 | | return; |
| | | 8500 | | } |
| | | 8501 | | } |
| | | 8502 | | catch (Exception ex) |
| | | 8503 | | { |
| | | 8504 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | | 8505 | | self.completedCount = CompleteCount; |
| | | 8506 | | self.completionSource.TrySetException(ex); |
| | | 8507 | | return; |
| | | 8508 | | } |
| | | 8509 | | |
| | | 8510 | | SUCCESS: |
| | | 8511 | | if (!self.TrySetResult()) |
| | | 8512 | | { |
| | | 8513 | | if (self.syncRunning) return; |
| | | 8514 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | | 8515 | | try |
| | | 8516 | | { |
| | | 8517 | | self.awaiter10 = self.enumerator10.MoveNextAsync().GetAwaiter(); |
| | | 8518 | | } |
| | | 8519 | | catch (Exception ex) |
| | | 8520 | | { |
| | | 8521 | | self.completedCount = CompleteCount; |
| | | 8522 | | self.completionSource.TrySetException(ex); |
| | | 8523 | | return; |
| | | 8524 | | } |
| | | 8525 | | |
| | | 8526 | | self.awaiter10.SourceOnCompleted(Completed10Delegate, self); |
| | | 8527 | | } |
| | | 8528 | | return; |
| | | 8529 | | COMPLETE: |
| | | 8530 | | self.completionSource.TrySetResult(false); |
| | | 8531 | | return; |
| | | 8532 | | } |
| | | 8533 | | |
| | | 8534 | | static void Completed11(object state) |
| | | 8535 | | { |
| | | 8536 | | var self = (_CombineLatest)state; |
| | | 8537 | | self.running11 = false; |
| | | 8538 | | |
| | | 8539 | | try |
| | | 8540 | | { |
| | | 8541 | | if (self.awaiter11.GetResult()) |
| | | 8542 | | { |
| | | 8543 | | self.hasCurrent11 = true; |
| | | 8544 | | self.current11 = self.enumerator11.Current; |
| | | 8545 | | goto SUCCESS; |
| | | 8546 | | } |
| | | 8547 | | else |
| | | 8548 | | { |
| | | 8549 | | self.running11 = true; // as complete, no more call MoveNextAsync. |
| | | 8550 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 8551 | | { |
| | | 8552 | | goto COMPLETE; |
| | | 8553 | | } |
| | | 8554 | | return; |
| | | 8555 | | } |
| | | 8556 | | } |
| | | 8557 | | catch (Exception ex) |
| | | 8558 | | { |
| | | 8559 | | self.running11 = true; // as complete, no more call MoveNextAsync. |
| | | 8560 | | self.completedCount = CompleteCount; |
| | | 8561 | | self.completionSource.TrySetException(ex); |
| | | 8562 | | return; |
| | | 8563 | | } |
| | | 8564 | | |
| | | 8565 | | SUCCESS: |
| | | 8566 | | if (!self.TrySetResult()) |
| | | 8567 | | { |
| | | 8568 | | if (self.syncRunning) return; |
| | | 8569 | | self.running11 = true; // as complete, no more call MoveNextAsync. |
| | | 8570 | | try |
| | | 8571 | | { |
| | | 8572 | | self.awaiter11 = self.enumerator11.MoveNextAsync().GetAwaiter(); |
| | | 8573 | | } |
| | | 8574 | | catch (Exception ex) |
| | | 8575 | | { |
| | | 8576 | | self.completedCount = CompleteCount; |
| | | 8577 | | self.completionSource.TrySetException(ex); |
| | | 8578 | | return; |
| | | 8579 | | } |
| | | 8580 | | |
| | | 8581 | | self.awaiter11.SourceOnCompleted(Completed11Delegate, self); |
| | | 8582 | | } |
| | | 8583 | | return; |
| | | 8584 | | COMPLETE: |
| | | 8585 | | self.completionSource.TrySetResult(false); |
| | | 8586 | | return; |
| | | 8587 | | } |
| | | 8588 | | |
| | | 8589 | | static void Completed12(object state) |
| | | 8590 | | { |
| | | 8591 | | var self = (_CombineLatest)state; |
| | | 8592 | | self.running12 = false; |
| | | 8593 | | |
| | | 8594 | | try |
| | | 8595 | | { |
| | | 8596 | | if (self.awaiter12.GetResult()) |
| | | 8597 | | { |
| | | 8598 | | self.hasCurrent12 = true; |
| | | 8599 | | self.current12 = self.enumerator12.Current; |
| | | 8600 | | goto SUCCESS; |
| | | 8601 | | } |
| | | 8602 | | else |
| | | 8603 | | { |
| | | 8604 | | self.running12 = true; // as complete, no more call MoveNextAsync. |
| | | 8605 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 8606 | | { |
| | | 8607 | | goto COMPLETE; |
| | | 8608 | | } |
| | | 8609 | | return; |
| | | 8610 | | } |
| | | 8611 | | } |
| | | 8612 | | catch (Exception ex) |
| | | 8613 | | { |
| | | 8614 | | self.running12 = true; // as complete, no more call MoveNextAsync. |
| | | 8615 | | self.completedCount = CompleteCount; |
| | | 8616 | | self.completionSource.TrySetException(ex); |
| | | 8617 | | return; |
| | | 8618 | | } |
| | | 8619 | | |
| | | 8620 | | SUCCESS: |
| | | 8621 | | if (!self.TrySetResult()) |
| | | 8622 | | { |
| | | 8623 | | if (self.syncRunning) return; |
| | | 8624 | | self.running12 = true; // as complete, no more call MoveNextAsync. |
| | | 8625 | | try |
| | | 8626 | | { |
| | | 8627 | | self.awaiter12 = self.enumerator12.MoveNextAsync().GetAwaiter(); |
| | | 8628 | | } |
| | | 8629 | | catch (Exception ex) |
| | | 8630 | | { |
| | | 8631 | | self.completedCount = CompleteCount; |
| | | 8632 | | self.completionSource.TrySetException(ex); |
| | | 8633 | | return; |
| | | 8634 | | } |
| | | 8635 | | |
| | | 8636 | | self.awaiter12.SourceOnCompleted(Completed12Delegate, self); |
| | | 8637 | | } |
| | | 8638 | | return; |
| | | 8639 | | COMPLETE: |
| | | 8640 | | self.completionSource.TrySetResult(false); |
| | | 8641 | | return; |
| | | 8642 | | } |
| | | 8643 | | |
| | | 8644 | | static void Completed13(object state) |
| | | 8645 | | { |
| | | 8646 | | var self = (_CombineLatest)state; |
| | | 8647 | | self.running13 = false; |
| | | 8648 | | |
| | | 8649 | | try |
| | | 8650 | | { |
| | | 8651 | | if (self.awaiter13.GetResult()) |
| | | 8652 | | { |
| | | 8653 | | self.hasCurrent13 = true; |
| | | 8654 | | self.current13 = self.enumerator13.Current; |
| | | 8655 | | goto SUCCESS; |
| | | 8656 | | } |
| | | 8657 | | else |
| | | 8658 | | { |
| | | 8659 | | self.running13 = true; // as complete, no more call MoveNextAsync. |
| | | 8660 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 8661 | | { |
| | | 8662 | | goto COMPLETE; |
| | | 8663 | | } |
| | | 8664 | | return; |
| | | 8665 | | } |
| | | 8666 | | } |
| | | 8667 | | catch (Exception ex) |
| | | 8668 | | { |
| | | 8669 | | self.running13 = true; // as complete, no more call MoveNextAsync. |
| | | 8670 | | self.completedCount = CompleteCount; |
| | | 8671 | | self.completionSource.TrySetException(ex); |
| | | 8672 | | return; |
| | | 8673 | | } |
| | | 8674 | | |
| | | 8675 | | SUCCESS: |
| | | 8676 | | if (!self.TrySetResult()) |
| | | 8677 | | { |
| | | 8678 | | if (self.syncRunning) return; |
| | | 8679 | | self.running13 = true; // as complete, no more call MoveNextAsync. |
| | | 8680 | | try |
| | | 8681 | | { |
| | | 8682 | | self.awaiter13 = self.enumerator13.MoveNextAsync().GetAwaiter(); |
| | | 8683 | | } |
| | | 8684 | | catch (Exception ex) |
| | | 8685 | | { |
| | | 8686 | | self.completedCount = CompleteCount; |
| | | 8687 | | self.completionSource.TrySetException(ex); |
| | | 8688 | | return; |
| | | 8689 | | } |
| | | 8690 | | |
| | | 8691 | | self.awaiter13.SourceOnCompleted(Completed13Delegate, self); |
| | | 8692 | | } |
| | | 8693 | | return; |
| | | 8694 | | COMPLETE: |
| | | 8695 | | self.completionSource.TrySetResult(false); |
| | | 8696 | | return; |
| | | 8697 | | } |
| | | 8698 | | |
| | | 8699 | | bool TrySetResult() |
| | | 8700 | | { |
| | | 8701 | | if (hasCurrent1 && hasCurrent2 && hasCurrent3 && hasCurrent4 && hasCurrent5 && hasCurrent6 && hasCurrent |
| | | 8702 | | { |
| | | 8703 | | result = resultSelector(current1, current2, current3, current4, current5, current6, current7, curren |
| | | 8704 | | completionSource.TrySetResult(true); |
| | | 8705 | | return true; |
| | | 8706 | | } |
| | | 8707 | | else |
| | | 8708 | | { |
| | | 8709 | | return false; |
| | | 8710 | | } |
| | | 8711 | | } |
| | | 8712 | | |
| | | 8713 | | public async UniTask DisposeAsync() |
| | | 8714 | | { |
| | | 8715 | | TaskTracker.RemoveTracking(this); |
| | | 8716 | | if (enumerator1 != null) |
| | | 8717 | | { |
| | | 8718 | | await enumerator1.DisposeAsync(); |
| | | 8719 | | } |
| | | 8720 | | if (enumerator2 != null) |
| | | 8721 | | { |
| | | 8722 | | await enumerator2.DisposeAsync(); |
| | | 8723 | | } |
| | | 8724 | | if (enumerator3 != null) |
| | | 8725 | | { |
| | | 8726 | | await enumerator3.DisposeAsync(); |
| | | 8727 | | } |
| | | 8728 | | if (enumerator4 != null) |
| | | 8729 | | { |
| | | 8730 | | await enumerator4.DisposeAsync(); |
| | | 8731 | | } |
| | | 8732 | | if (enumerator5 != null) |
| | | 8733 | | { |
| | | 8734 | | await enumerator5.DisposeAsync(); |
| | | 8735 | | } |
| | | 8736 | | if (enumerator6 != null) |
| | | 8737 | | { |
| | | 8738 | | await enumerator6.DisposeAsync(); |
| | | 8739 | | } |
| | | 8740 | | if (enumerator7 != null) |
| | | 8741 | | { |
| | | 8742 | | await enumerator7.DisposeAsync(); |
| | | 8743 | | } |
| | | 8744 | | if (enumerator8 != null) |
| | | 8745 | | { |
| | | 8746 | | await enumerator8.DisposeAsync(); |
| | | 8747 | | } |
| | | 8748 | | if (enumerator9 != null) |
| | | 8749 | | { |
| | | 8750 | | await enumerator9.DisposeAsync(); |
| | | 8751 | | } |
| | | 8752 | | if (enumerator10 != null) |
| | | 8753 | | { |
| | | 8754 | | await enumerator10.DisposeAsync(); |
| | | 8755 | | } |
| | | 8756 | | if (enumerator11 != null) |
| | | 8757 | | { |
| | | 8758 | | await enumerator11.DisposeAsync(); |
| | | 8759 | | } |
| | | 8760 | | if (enumerator12 != null) |
| | | 8761 | | { |
| | | 8762 | | await enumerator12.DisposeAsync(); |
| | | 8763 | | } |
| | | 8764 | | if (enumerator13 != null) |
| | | 8765 | | { |
| | | 8766 | | await enumerator13.DisposeAsync(); |
| | | 8767 | | } |
| | | 8768 | | } |
| | | 8769 | | } |
| | | 8770 | | } |
| | | 8771 | | |
| | | 8772 | | internal class CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult> : IUniTaskAsyncEn |
| | | 8773 | | { |
| | | 8774 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 8775 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 8776 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 8777 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 8778 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 8779 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 8780 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 8781 | | readonly IUniTaskAsyncEnumerable<T8> source8; |
| | | 8782 | | readonly IUniTaskAsyncEnumerable<T9> source9; |
| | | 8783 | | readonly IUniTaskAsyncEnumerable<T10> source10; |
| | | 8784 | | readonly IUniTaskAsyncEnumerable<T11> source11; |
| | | 8785 | | readonly IUniTaskAsyncEnumerable<T12> source12; |
| | | 8786 | | readonly IUniTaskAsyncEnumerable<T13> source13; |
| | | 8787 | | readonly IUniTaskAsyncEnumerable<T14> source14; |
| | | 8788 | | |
| | | 8789 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult> resultSelector; |
| | | 8790 | | |
| | 0 | 8791 | | public CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyncEnum |
| | 0 | 8792 | | { |
| | 0 | 8793 | | this.source1 = source1; |
| | 0 | 8794 | | this.source2 = source2; |
| | 0 | 8795 | | this.source3 = source3; |
| | 0 | 8796 | | this.source4 = source4; |
| | 0 | 8797 | | this.source5 = source5; |
| | 0 | 8798 | | this.source6 = source6; |
| | 0 | 8799 | | this.source7 = source7; |
| | 0 | 8800 | | this.source8 = source8; |
| | 0 | 8801 | | this.source9 = source9; |
| | 0 | 8802 | | this.source10 = source10; |
| | 0 | 8803 | | this.source11 = source11; |
| | 0 | 8804 | | this.source12 = source12; |
| | 0 | 8805 | | this.source13 = source13; |
| | 0 | 8806 | | this.source14 = source14; |
| | | 8807 | | |
| | 0 | 8808 | | this.resultSelector = resultSelector; |
| | 0 | 8809 | | } |
| | | 8810 | | |
| | | 8811 | | public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default) |
| | 0 | 8812 | | { |
| | 0 | 8813 | | return new _CombineLatest(source1, source2, source3, source4, source5, source6, source7, source8, source9, s |
| | 0 | 8814 | | } |
| | | 8815 | | |
| | | 8816 | | class _CombineLatest : MoveNextSource, IUniTaskAsyncEnumerator<TResult> |
| | | 8817 | | { |
| | 0 | 8818 | | static readonly Action<object> Completed1Delegate = Completed1; |
| | 0 | 8819 | | static readonly Action<object> Completed2Delegate = Completed2; |
| | 0 | 8820 | | static readonly Action<object> Completed3Delegate = Completed3; |
| | 0 | 8821 | | static readonly Action<object> Completed4Delegate = Completed4; |
| | 0 | 8822 | | static readonly Action<object> Completed5Delegate = Completed5; |
| | 0 | 8823 | | static readonly Action<object> Completed6Delegate = Completed6; |
| | 0 | 8824 | | static readonly Action<object> Completed7Delegate = Completed7; |
| | 0 | 8825 | | static readonly Action<object> Completed8Delegate = Completed8; |
| | 0 | 8826 | | static readonly Action<object> Completed9Delegate = Completed9; |
| | 0 | 8827 | | static readonly Action<object> Completed10Delegate = Completed10; |
| | 0 | 8828 | | static readonly Action<object> Completed11Delegate = Completed11; |
| | 0 | 8829 | | static readonly Action<object> Completed12Delegate = Completed12; |
| | 0 | 8830 | | static readonly Action<object> Completed13Delegate = Completed13; |
| | 0 | 8831 | | static readonly Action<object> Completed14Delegate = Completed14; |
| | | 8832 | | const int CompleteCount = 14; |
| | | 8833 | | |
| | | 8834 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 8835 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 8836 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 8837 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 8838 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 8839 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 8840 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 8841 | | readonly IUniTaskAsyncEnumerable<T8> source8; |
| | | 8842 | | readonly IUniTaskAsyncEnumerable<T9> source9; |
| | | 8843 | | readonly IUniTaskAsyncEnumerable<T10> source10; |
| | | 8844 | | readonly IUniTaskAsyncEnumerable<T11> source11; |
| | | 8845 | | readonly IUniTaskAsyncEnumerable<T12> source12; |
| | | 8846 | | readonly IUniTaskAsyncEnumerable<T13> source13; |
| | | 8847 | | readonly IUniTaskAsyncEnumerable<T14> source14; |
| | | 8848 | | |
| | | 8849 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult> resultSelector; |
| | | 8850 | | CancellationToken cancellationToken; |
| | | 8851 | | |
| | | 8852 | | IUniTaskAsyncEnumerator<T1> enumerator1; |
| | | 8853 | | UniTask<bool>.Awaiter awaiter1; |
| | | 8854 | | bool hasCurrent1; |
| | | 8855 | | bool running1; |
| | | 8856 | | T1 current1; |
| | | 8857 | | |
| | | 8858 | | IUniTaskAsyncEnumerator<T2> enumerator2; |
| | | 8859 | | UniTask<bool>.Awaiter awaiter2; |
| | | 8860 | | bool hasCurrent2; |
| | | 8861 | | bool running2; |
| | | 8862 | | T2 current2; |
| | | 8863 | | |
| | | 8864 | | IUniTaskAsyncEnumerator<T3> enumerator3; |
| | | 8865 | | UniTask<bool>.Awaiter awaiter3; |
| | | 8866 | | bool hasCurrent3; |
| | | 8867 | | bool running3; |
| | | 8868 | | T3 current3; |
| | | 8869 | | |
| | | 8870 | | IUniTaskAsyncEnumerator<T4> enumerator4; |
| | | 8871 | | UniTask<bool>.Awaiter awaiter4; |
| | | 8872 | | bool hasCurrent4; |
| | | 8873 | | bool running4; |
| | | 8874 | | T4 current4; |
| | | 8875 | | |
| | | 8876 | | IUniTaskAsyncEnumerator<T5> enumerator5; |
| | | 8877 | | UniTask<bool>.Awaiter awaiter5; |
| | | 8878 | | bool hasCurrent5; |
| | | 8879 | | bool running5; |
| | | 8880 | | T5 current5; |
| | | 8881 | | |
| | | 8882 | | IUniTaskAsyncEnumerator<T6> enumerator6; |
| | | 8883 | | UniTask<bool>.Awaiter awaiter6; |
| | | 8884 | | bool hasCurrent6; |
| | | 8885 | | bool running6; |
| | | 8886 | | T6 current6; |
| | | 8887 | | |
| | | 8888 | | IUniTaskAsyncEnumerator<T7> enumerator7; |
| | | 8889 | | UniTask<bool>.Awaiter awaiter7; |
| | | 8890 | | bool hasCurrent7; |
| | | 8891 | | bool running7; |
| | | 8892 | | T7 current7; |
| | | 8893 | | |
| | | 8894 | | IUniTaskAsyncEnumerator<T8> enumerator8; |
| | | 8895 | | UniTask<bool>.Awaiter awaiter8; |
| | | 8896 | | bool hasCurrent8; |
| | | 8897 | | bool running8; |
| | | 8898 | | T8 current8; |
| | | 8899 | | |
| | | 8900 | | IUniTaskAsyncEnumerator<T9> enumerator9; |
| | | 8901 | | UniTask<bool>.Awaiter awaiter9; |
| | | 8902 | | bool hasCurrent9; |
| | | 8903 | | bool running9; |
| | | 8904 | | T9 current9; |
| | | 8905 | | |
| | | 8906 | | IUniTaskAsyncEnumerator<T10> enumerator10; |
| | | 8907 | | UniTask<bool>.Awaiter awaiter10; |
| | | 8908 | | bool hasCurrent10; |
| | | 8909 | | bool running10; |
| | | 8910 | | T10 current10; |
| | | 8911 | | |
| | | 8912 | | IUniTaskAsyncEnumerator<T11> enumerator11; |
| | | 8913 | | UniTask<bool>.Awaiter awaiter11; |
| | | 8914 | | bool hasCurrent11; |
| | | 8915 | | bool running11; |
| | | 8916 | | T11 current11; |
| | | 8917 | | |
| | | 8918 | | IUniTaskAsyncEnumerator<T12> enumerator12; |
| | | 8919 | | UniTask<bool>.Awaiter awaiter12; |
| | | 8920 | | bool hasCurrent12; |
| | | 8921 | | bool running12; |
| | | 8922 | | T12 current12; |
| | | 8923 | | |
| | | 8924 | | IUniTaskAsyncEnumerator<T13> enumerator13; |
| | | 8925 | | UniTask<bool>.Awaiter awaiter13; |
| | | 8926 | | bool hasCurrent13; |
| | | 8927 | | bool running13; |
| | | 8928 | | T13 current13; |
| | | 8929 | | |
| | | 8930 | | IUniTaskAsyncEnumerator<T14> enumerator14; |
| | | 8931 | | UniTask<bool>.Awaiter awaiter14; |
| | | 8932 | | bool hasCurrent14; |
| | | 8933 | | bool running14; |
| | | 8934 | | T14 current14; |
| | | 8935 | | |
| | | 8936 | | int completedCount; |
| | | 8937 | | bool syncRunning; |
| | | 8938 | | TResult result; |
| | | 8939 | | |
| | 0 | 8940 | | public _CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyn |
| | 0 | 8941 | | { |
| | 0 | 8942 | | this.source1 = source1; |
| | 0 | 8943 | | this.source2 = source2; |
| | 0 | 8944 | | this.source3 = source3; |
| | 0 | 8945 | | this.source4 = source4; |
| | 0 | 8946 | | this.source5 = source5; |
| | 0 | 8947 | | this.source6 = source6; |
| | 0 | 8948 | | this.source7 = source7; |
| | 0 | 8949 | | this.source8 = source8; |
| | 0 | 8950 | | this.source9 = source9; |
| | 0 | 8951 | | this.source10 = source10; |
| | 0 | 8952 | | this.source11 = source11; |
| | 0 | 8953 | | this.source12 = source12; |
| | 0 | 8954 | | this.source13 = source13; |
| | 0 | 8955 | | this.source14 = source14; |
| | | 8956 | | |
| | 0 | 8957 | | this.resultSelector = resultSelector; |
| | 0 | 8958 | | this.cancellationToken = cancellationToken; |
| | 0 | 8959 | | TaskTracker.TrackActiveTask(this, 3); |
| | 0 | 8960 | | } |
| | | 8961 | | |
| | 0 | 8962 | | public TResult Current => result; |
| | | 8963 | | |
| | | 8964 | | public UniTask<bool> MoveNextAsync() |
| | 0 | 8965 | | { |
| | 0 | 8966 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 8967 | | if (completedCount == CompleteCount) return CompletedTasks.False; |
| | | 8968 | | |
| | 0 | 8969 | | if (enumerator1 == null) |
| | 0 | 8970 | | { |
| | 0 | 8971 | | enumerator1 = source1.GetAsyncEnumerator(cancellationToken); |
| | 0 | 8972 | | enumerator2 = source2.GetAsyncEnumerator(cancellationToken); |
| | 0 | 8973 | | enumerator3 = source3.GetAsyncEnumerator(cancellationToken); |
| | 0 | 8974 | | enumerator4 = source4.GetAsyncEnumerator(cancellationToken); |
| | 0 | 8975 | | enumerator5 = source5.GetAsyncEnumerator(cancellationToken); |
| | 0 | 8976 | | enumerator6 = source6.GetAsyncEnumerator(cancellationToken); |
| | 0 | 8977 | | enumerator7 = source7.GetAsyncEnumerator(cancellationToken); |
| | 0 | 8978 | | enumerator8 = source8.GetAsyncEnumerator(cancellationToken); |
| | 0 | 8979 | | enumerator9 = source9.GetAsyncEnumerator(cancellationToken); |
| | 0 | 8980 | | enumerator10 = source10.GetAsyncEnumerator(cancellationToken); |
| | 0 | 8981 | | enumerator11 = source11.GetAsyncEnumerator(cancellationToken); |
| | 0 | 8982 | | enumerator12 = source12.GetAsyncEnumerator(cancellationToken); |
| | 0 | 8983 | | enumerator13 = source13.GetAsyncEnumerator(cancellationToken); |
| | 0 | 8984 | | enumerator14 = source14.GetAsyncEnumerator(cancellationToken); |
| | 0 | 8985 | | } |
| | | 8986 | | |
| | 0 | 8987 | | completionSource.Reset(); |
| | | 8988 | | |
| | 0 | 8989 | | AGAIN: |
| | 0 | 8990 | | syncRunning = true; |
| | 0 | 8991 | | if (!running1) |
| | 0 | 8992 | | { |
| | 0 | 8993 | | running1 = true; |
| | 0 | 8994 | | awaiter1 = enumerator1.MoveNextAsync().GetAwaiter(); |
| | 0 | 8995 | | if (awaiter1.IsCompleted) |
| | 0 | 8996 | | { |
| | 0 | 8997 | | Completed1(this); |
| | 0 | 8998 | | } |
| | | 8999 | | else |
| | 0 | 9000 | | { |
| | 0 | 9001 | | awaiter1.SourceOnCompleted(Completed1Delegate, this); |
| | 0 | 9002 | | } |
| | 0 | 9003 | | } |
| | 0 | 9004 | | if (!running2) |
| | 0 | 9005 | | { |
| | 0 | 9006 | | running2 = true; |
| | 0 | 9007 | | awaiter2 = enumerator2.MoveNextAsync().GetAwaiter(); |
| | 0 | 9008 | | if (awaiter2.IsCompleted) |
| | 0 | 9009 | | { |
| | 0 | 9010 | | Completed2(this); |
| | 0 | 9011 | | } |
| | | 9012 | | else |
| | 0 | 9013 | | { |
| | 0 | 9014 | | awaiter2.SourceOnCompleted(Completed2Delegate, this); |
| | 0 | 9015 | | } |
| | 0 | 9016 | | } |
| | 0 | 9017 | | if (!running3) |
| | 0 | 9018 | | { |
| | 0 | 9019 | | running3 = true; |
| | 0 | 9020 | | awaiter3 = enumerator3.MoveNextAsync().GetAwaiter(); |
| | 0 | 9021 | | if (awaiter3.IsCompleted) |
| | 0 | 9022 | | { |
| | 0 | 9023 | | Completed3(this); |
| | 0 | 9024 | | } |
| | | 9025 | | else |
| | 0 | 9026 | | { |
| | 0 | 9027 | | awaiter3.SourceOnCompleted(Completed3Delegate, this); |
| | 0 | 9028 | | } |
| | 0 | 9029 | | } |
| | 0 | 9030 | | if (!running4) |
| | 0 | 9031 | | { |
| | 0 | 9032 | | running4 = true; |
| | 0 | 9033 | | awaiter4 = enumerator4.MoveNextAsync().GetAwaiter(); |
| | 0 | 9034 | | if (awaiter4.IsCompleted) |
| | 0 | 9035 | | { |
| | 0 | 9036 | | Completed4(this); |
| | 0 | 9037 | | } |
| | | 9038 | | else |
| | 0 | 9039 | | { |
| | 0 | 9040 | | awaiter4.SourceOnCompleted(Completed4Delegate, this); |
| | 0 | 9041 | | } |
| | 0 | 9042 | | } |
| | 0 | 9043 | | if (!running5) |
| | 0 | 9044 | | { |
| | 0 | 9045 | | running5 = true; |
| | 0 | 9046 | | awaiter5 = enumerator5.MoveNextAsync().GetAwaiter(); |
| | 0 | 9047 | | if (awaiter5.IsCompleted) |
| | 0 | 9048 | | { |
| | 0 | 9049 | | Completed5(this); |
| | 0 | 9050 | | } |
| | | 9051 | | else |
| | 0 | 9052 | | { |
| | 0 | 9053 | | awaiter5.SourceOnCompleted(Completed5Delegate, this); |
| | 0 | 9054 | | } |
| | 0 | 9055 | | } |
| | 0 | 9056 | | if (!running6) |
| | 0 | 9057 | | { |
| | 0 | 9058 | | running6 = true; |
| | 0 | 9059 | | awaiter6 = enumerator6.MoveNextAsync().GetAwaiter(); |
| | 0 | 9060 | | if (awaiter6.IsCompleted) |
| | 0 | 9061 | | { |
| | 0 | 9062 | | Completed6(this); |
| | 0 | 9063 | | } |
| | | 9064 | | else |
| | 0 | 9065 | | { |
| | 0 | 9066 | | awaiter6.SourceOnCompleted(Completed6Delegate, this); |
| | 0 | 9067 | | } |
| | 0 | 9068 | | } |
| | 0 | 9069 | | if (!running7) |
| | 0 | 9070 | | { |
| | 0 | 9071 | | running7 = true; |
| | 0 | 9072 | | awaiter7 = enumerator7.MoveNextAsync().GetAwaiter(); |
| | 0 | 9073 | | if (awaiter7.IsCompleted) |
| | 0 | 9074 | | { |
| | 0 | 9075 | | Completed7(this); |
| | 0 | 9076 | | } |
| | | 9077 | | else |
| | 0 | 9078 | | { |
| | 0 | 9079 | | awaiter7.SourceOnCompleted(Completed7Delegate, this); |
| | 0 | 9080 | | } |
| | 0 | 9081 | | } |
| | 0 | 9082 | | if (!running8) |
| | 0 | 9083 | | { |
| | 0 | 9084 | | running8 = true; |
| | 0 | 9085 | | awaiter8 = enumerator8.MoveNextAsync().GetAwaiter(); |
| | 0 | 9086 | | if (awaiter8.IsCompleted) |
| | 0 | 9087 | | { |
| | 0 | 9088 | | Completed8(this); |
| | 0 | 9089 | | } |
| | | 9090 | | else |
| | 0 | 9091 | | { |
| | 0 | 9092 | | awaiter8.SourceOnCompleted(Completed8Delegate, this); |
| | 0 | 9093 | | } |
| | 0 | 9094 | | } |
| | 0 | 9095 | | if (!running9) |
| | 0 | 9096 | | { |
| | 0 | 9097 | | running9 = true; |
| | 0 | 9098 | | awaiter9 = enumerator9.MoveNextAsync().GetAwaiter(); |
| | 0 | 9099 | | if (awaiter9.IsCompleted) |
| | 0 | 9100 | | { |
| | 0 | 9101 | | Completed9(this); |
| | 0 | 9102 | | } |
| | | 9103 | | else |
| | 0 | 9104 | | { |
| | 0 | 9105 | | awaiter9.SourceOnCompleted(Completed9Delegate, this); |
| | 0 | 9106 | | } |
| | 0 | 9107 | | } |
| | 0 | 9108 | | if (!running10) |
| | 0 | 9109 | | { |
| | 0 | 9110 | | running10 = true; |
| | 0 | 9111 | | awaiter10 = enumerator10.MoveNextAsync().GetAwaiter(); |
| | 0 | 9112 | | if (awaiter10.IsCompleted) |
| | 0 | 9113 | | { |
| | 0 | 9114 | | Completed10(this); |
| | 0 | 9115 | | } |
| | | 9116 | | else |
| | 0 | 9117 | | { |
| | 0 | 9118 | | awaiter10.SourceOnCompleted(Completed10Delegate, this); |
| | 0 | 9119 | | } |
| | 0 | 9120 | | } |
| | 0 | 9121 | | if (!running11) |
| | 0 | 9122 | | { |
| | 0 | 9123 | | running11 = true; |
| | 0 | 9124 | | awaiter11 = enumerator11.MoveNextAsync().GetAwaiter(); |
| | 0 | 9125 | | if (awaiter11.IsCompleted) |
| | 0 | 9126 | | { |
| | 0 | 9127 | | Completed11(this); |
| | 0 | 9128 | | } |
| | | 9129 | | else |
| | 0 | 9130 | | { |
| | 0 | 9131 | | awaiter11.SourceOnCompleted(Completed11Delegate, this); |
| | 0 | 9132 | | } |
| | 0 | 9133 | | } |
| | 0 | 9134 | | if (!running12) |
| | 0 | 9135 | | { |
| | 0 | 9136 | | running12 = true; |
| | 0 | 9137 | | awaiter12 = enumerator12.MoveNextAsync().GetAwaiter(); |
| | 0 | 9138 | | if (awaiter12.IsCompleted) |
| | 0 | 9139 | | { |
| | 0 | 9140 | | Completed12(this); |
| | 0 | 9141 | | } |
| | | 9142 | | else |
| | 0 | 9143 | | { |
| | 0 | 9144 | | awaiter12.SourceOnCompleted(Completed12Delegate, this); |
| | 0 | 9145 | | } |
| | 0 | 9146 | | } |
| | 0 | 9147 | | if (!running13) |
| | 0 | 9148 | | { |
| | 0 | 9149 | | running13 = true; |
| | 0 | 9150 | | awaiter13 = enumerator13.MoveNextAsync().GetAwaiter(); |
| | 0 | 9151 | | if (awaiter13.IsCompleted) |
| | 0 | 9152 | | { |
| | 0 | 9153 | | Completed13(this); |
| | 0 | 9154 | | } |
| | | 9155 | | else |
| | 0 | 9156 | | { |
| | 0 | 9157 | | awaiter13.SourceOnCompleted(Completed13Delegate, this); |
| | 0 | 9158 | | } |
| | 0 | 9159 | | } |
| | 0 | 9160 | | if (!running14) |
| | 0 | 9161 | | { |
| | 0 | 9162 | | running14 = true; |
| | 0 | 9163 | | awaiter14 = enumerator14.MoveNextAsync().GetAwaiter(); |
| | 0 | 9164 | | if (awaiter14.IsCompleted) |
| | 0 | 9165 | | { |
| | 0 | 9166 | | Completed14(this); |
| | 0 | 9167 | | } |
| | | 9168 | | else |
| | 0 | 9169 | | { |
| | 0 | 9170 | | awaiter14.SourceOnCompleted(Completed14Delegate, this); |
| | 0 | 9171 | | } |
| | 0 | 9172 | | } |
| | | 9173 | | |
| | 0 | 9174 | | if (!running1 || !running2 || !running3 || !running4 || !running5 || !running6 || !running7 || !running8 |
| | 0 | 9175 | | { |
| | 0 | 9176 | | goto AGAIN; |
| | | 9177 | | } |
| | 0 | 9178 | | syncRunning = false; |
| | | 9179 | | |
| | 0 | 9180 | | return new UniTask<bool>(this, completionSource.Version); |
| | 0 | 9181 | | } |
| | | 9182 | | |
| | | 9183 | | static void Completed1(object state) |
| | 0 | 9184 | | { |
| | 0 | 9185 | | var self = (_CombineLatest)state; |
| | 0 | 9186 | | self.running1 = false; |
| | | 9187 | | |
| | | 9188 | | try |
| | 0 | 9189 | | { |
| | 0 | 9190 | | if (self.awaiter1.GetResult()) |
| | 0 | 9191 | | { |
| | 0 | 9192 | | self.hasCurrent1 = true; |
| | 0 | 9193 | | self.current1 = self.enumerator1.Current; |
| | 0 | 9194 | | goto SUCCESS; |
| | | 9195 | | } |
| | | 9196 | | else |
| | 0 | 9197 | | { |
| | 0 | 9198 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9199 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | 0 | 9200 | | { |
| | 0 | 9201 | | goto COMPLETE; |
| | | 9202 | | } |
| | 0 | 9203 | | return; |
| | | 9204 | | } |
| | | 9205 | | } |
| | 0 | 9206 | | catch (Exception ex) |
| | 0 | 9207 | | { |
| | 0 | 9208 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9209 | | self.completedCount = CompleteCount; |
| | 0 | 9210 | | self.completionSource.TrySetException(ex); |
| | 0 | 9211 | | return; |
| | | 9212 | | } |
| | | 9213 | | |
| | 0 | 9214 | | SUCCESS: |
| | 0 | 9215 | | if (!self.TrySetResult()) |
| | 0 | 9216 | | { |
| | 0 | 9217 | | if (self.syncRunning) return; |
| | 0 | 9218 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 9219 | | try |
| | 0 | 9220 | | { |
| | 0 | 9221 | | self.awaiter1 = self.enumerator1.MoveNextAsync().GetAwaiter(); |
| | 0 | 9222 | | } |
| | 0 | 9223 | | catch (Exception ex) |
| | 0 | 9224 | | { |
| | 0 | 9225 | | self.completedCount = CompleteCount; |
| | 0 | 9226 | | self.completionSource.TrySetException(ex); |
| | 0 | 9227 | | return; |
| | | 9228 | | } |
| | | 9229 | | |
| | 0 | 9230 | | self.awaiter1.SourceOnCompleted(Completed1Delegate, self); |
| | 0 | 9231 | | } |
| | 0 | 9232 | | return; |
| | 0 | 9233 | | COMPLETE: |
| | 0 | 9234 | | self.completionSource.TrySetResult(false); |
| | 0 | 9235 | | return; |
| | 0 | 9236 | | } |
| | | 9237 | | |
| | | 9238 | | static void Completed2(object state) |
| | 0 | 9239 | | { |
| | 0 | 9240 | | var self = (_CombineLatest)state; |
| | 0 | 9241 | | self.running2 = false; |
| | | 9242 | | |
| | | 9243 | | try |
| | 0 | 9244 | | { |
| | 0 | 9245 | | if (self.awaiter2.GetResult()) |
| | 0 | 9246 | | { |
| | 0 | 9247 | | self.hasCurrent2 = true; |
| | 0 | 9248 | | self.current2 = self.enumerator2.Current; |
| | 0 | 9249 | | goto SUCCESS; |
| | | 9250 | | } |
| | | 9251 | | else |
| | 0 | 9252 | | { |
| | 0 | 9253 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9254 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | 0 | 9255 | | { |
| | 0 | 9256 | | goto COMPLETE; |
| | | 9257 | | } |
| | 0 | 9258 | | return; |
| | | 9259 | | } |
| | | 9260 | | } |
| | 0 | 9261 | | catch (Exception ex) |
| | 0 | 9262 | | { |
| | 0 | 9263 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9264 | | self.completedCount = CompleteCount; |
| | 0 | 9265 | | self.completionSource.TrySetException(ex); |
| | 0 | 9266 | | return; |
| | | 9267 | | } |
| | | 9268 | | |
| | 0 | 9269 | | SUCCESS: |
| | 0 | 9270 | | if (!self.TrySetResult()) |
| | 0 | 9271 | | { |
| | 0 | 9272 | | if (self.syncRunning) return; |
| | 0 | 9273 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 9274 | | try |
| | 0 | 9275 | | { |
| | 0 | 9276 | | self.awaiter2 = self.enumerator2.MoveNextAsync().GetAwaiter(); |
| | 0 | 9277 | | } |
| | 0 | 9278 | | catch (Exception ex) |
| | 0 | 9279 | | { |
| | 0 | 9280 | | self.completedCount = CompleteCount; |
| | 0 | 9281 | | self.completionSource.TrySetException(ex); |
| | 0 | 9282 | | return; |
| | | 9283 | | } |
| | | 9284 | | |
| | 0 | 9285 | | self.awaiter2.SourceOnCompleted(Completed2Delegate, self); |
| | 0 | 9286 | | } |
| | 0 | 9287 | | return; |
| | 0 | 9288 | | COMPLETE: |
| | 0 | 9289 | | self.completionSource.TrySetResult(false); |
| | 0 | 9290 | | return; |
| | 0 | 9291 | | } |
| | | 9292 | | |
| | | 9293 | | static void Completed3(object state) |
| | 0 | 9294 | | { |
| | 0 | 9295 | | var self = (_CombineLatest)state; |
| | 0 | 9296 | | self.running3 = false; |
| | | 9297 | | |
| | | 9298 | | try |
| | 0 | 9299 | | { |
| | 0 | 9300 | | if (self.awaiter3.GetResult()) |
| | 0 | 9301 | | { |
| | 0 | 9302 | | self.hasCurrent3 = true; |
| | 0 | 9303 | | self.current3 = self.enumerator3.Current; |
| | 0 | 9304 | | goto SUCCESS; |
| | | 9305 | | } |
| | | 9306 | | else |
| | 0 | 9307 | | { |
| | 0 | 9308 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9309 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | 0 | 9310 | | { |
| | 0 | 9311 | | goto COMPLETE; |
| | | 9312 | | } |
| | 0 | 9313 | | return; |
| | | 9314 | | } |
| | | 9315 | | } |
| | 0 | 9316 | | catch (Exception ex) |
| | 0 | 9317 | | { |
| | 0 | 9318 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9319 | | self.completedCount = CompleteCount; |
| | 0 | 9320 | | self.completionSource.TrySetException(ex); |
| | 0 | 9321 | | return; |
| | | 9322 | | } |
| | | 9323 | | |
| | 0 | 9324 | | SUCCESS: |
| | 0 | 9325 | | if (!self.TrySetResult()) |
| | 0 | 9326 | | { |
| | 0 | 9327 | | if (self.syncRunning) return; |
| | 0 | 9328 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 9329 | | try |
| | 0 | 9330 | | { |
| | 0 | 9331 | | self.awaiter3 = self.enumerator3.MoveNextAsync().GetAwaiter(); |
| | 0 | 9332 | | } |
| | 0 | 9333 | | catch (Exception ex) |
| | 0 | 9334 | | { |
| | 0 | 9335 | | self.completedCount = CompleteCount; |
| | 0 | 9336 | | self.completionSource.TrySetException(ex); |
| | 0 | 9337 | | return; |
| | | 9338 | | } |
| | | 9339 | | |
| | 0 | 9340 | | self.awaiter3.SourceOnCompleted(Completed3Delegate, self); |
| | 0 | 9341 | | } |
| | 0 | 9342 | | return; |
| | 0 | 9343 | | COMPLETE: |
| | 0 | 9344 | | self.completionSource.TrySetResult(false); |
| | 0 | 9345 | | return; |
| | 0 | 9346 | | } |
| | | 9347 | | |
| | | 9348 | | static void Completed4(object state) |
| | 0 | 9349 | | { |
| | 0 | 9350 | | var self = (_CombineLatest)state; |
| | 0 | 9351 | | self.running4 = false; |
| | | 9352 | | |
| | | 9353 | | try |
| | 0 | 9354 | | { |
| | 0 | 9355 | | if (self.awaiter4.GetResult()) |
| | 0 | 9356 | | { |
| | 0 | 9357 | | self.hasCurrent4 = true; |
| | 0 | 9358 | | self.current4 = self.enumerator4.Current; |
| | 0 | 9359 | | goto SUCCESS; |
| | | 9360 | | } |
| | | 9361 | | else |
| | 0 | 9362 | | { |
| | 0 | 9363 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9364 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | 0 | 9365 | | { |
| | 0 | 9366 | | goto COMPLETE; |
| | | 9367 | | } |
| | 0 | 9368 | | return; |
| | | 9369 | | } |
| | | 9370 | | } |
| | 0 | 9371 | | catch (Exception ex) |
| | 0 | 9372 | | { |
| | 0 | 9373 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9374 | | self.completedCount = CompleteCount; |
| | 0 | 9375 | | self.completionSource.TrySetException(ex); |
| | 0 | 9376 | | return; |
| | | 9377 | | } |
| | | 9378 | | |
| | 0 | 9379 | | SUCCESS: |
| | 0 | 9380 | | if (!self.TrySetResult()) |
| | 0 | 9381 | | { |
| | 0 | 9382 | | if (self.syncRunning) return; |
| | 0 | 9383 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 9384 | | try |
| | 0 | 9385 | | { |
| | 0 | 9386 | | self.awaiter4 = self.enumerator4.MoveNextAsync().GetAwaiter(); |
| | 0 | 9387 | | } |
| | 0 | 9388 | | catch (Exception ex) |
| | 0 | 9389 | | { |
| | 0 | 9390 | | self.completedCount = CompleteCount; |
| | 0 | 9391 | | self.completionSource.TrySetException(ex); |
| | 0 | 9392 | | return; |
| | | 9393 | | } |
| | | 9394 | | |
| | 0 | 9395 | | self.awaiter4.SourceOnCompleted(Completed4Delegate, self); |
| | 0 | 9396 | | } |
| | 0 | 9397 | | return; |
| | 0 | 9398 | | COMPLETE: |
| | 0 | 9399 | | self.completionSource.TrySetResult(false); |
| | 0 | 9400 | | return; |
| | 0 | 9401 | | } |
| | | 9402 | | |
| | | 9403 | | static void Completed5(object state) |
| | 0 | 9404 | | { |
| | 0 | 9405 | | var self = (_CombineLatest)state; |
| | 0 | 9406 | | self.running5 = false; |
| | | 9407 | | |
| | | 9408 | | try |
| | 0 | 9409 | | { |
| | 0 | 9410 | | if (self.awaiter5.GetResult()) |
| | 0 | 9411 | | { |
| | 0 | 9412 | | self.hasCurrent5 = true; |
| | 0 | 9413 | | self.current5 = self.enumerator5.Current; |
| | 0 | 9414 | | goto SUCCESS; |
| | | 9415 | | } |
| | | 9416 | | else |
| | 0 | 9417 | | { |
| | 0 | 9418 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9419 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | 0 | 9420 | | { |
| | 0 | 9421 | | goto COMPLETE; |
| | | 9422 | | } |
| | 0 | 9423 | | return; |
| | | 9424 | | } |
| | | 9425 | | } |
| | 0 | 9426 | | catch (Exception ex) |
| | 0 | 9427 | | { |
| | 0 | 9428 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9429 | | self.completedCount = CompleteCount; |
| | 0 | 9430 | | self.completionSource.TrySetException(ex); |
| | 0 | 9431 | | return; |
| | | 9432 | | } |
| | | 9433 | | |
| | 0 | 9434 | | SUCCESS: |
| | 0 | 9435 | | if (!self.TrySetResult()) |
| | 0 | 9436 | | { |
| | 0 | 9437 | | if (self.syncRunning) return; |
| | 0 | 9438 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 9439 | | try |
| | 0 | 9440 | | { |
| | 0 | 9441 | | self.awaiter5 = self.enumerator5.MoveNextAsync().GetAwaiter(); |
| | 0 | 9442 | | } |
| | 0 | 9443 | | catch (Exception ex) |
| | 0 | 9444 | | { |
| | 0 | 9445 | | self.completedCount = CompleteCount; |
| | 0 | 9446 | | self.completionSource.TrySetException(ex); |
| | 0 | 9447 | | return; |
| | | 9448 | | } |
| | | 9449 | | |
| | 0 | 9450 | | self.awaiter5.SourceOnCompleted(Completed5Delegate, self); |
| | 0 | 9451 | | } |
| | 0 | 9452 | | return; |
| | 0 | 9453 | | COMPLETE: |
| | 0 | 9454 | | self.completionSource.TrySetResult(false); |
| | 0 | 9455 | | return; |
| | 0 | 9456 | | } |
| | | 9457 | | |
| | | 9458 | | static void Completed6(object state) |
| | 0 | 9459 | | { |
| | 0 | 9460 | | var self = (_CombineLatest)state; |
| | 0 | 9461 | | self.running6 = false; |
| | | 9462 | | |
| | | 9463 | | try |
| | 0 | 9464 | | { |
| | 0 | 9465 | | if (self.awaiter6.GetResult()) |
| | 0 | 9466 | | { |
| | 0 | 9467 | | self.hasCurrent6 = true; |
| | 0 | 9468 | | self.current6 = self.enumerator6.Current; |
| | 0 | 9469 | | goto SUCCESS; |
| | | 9470 | | } |
| | | 9471 | | else |
| | 0 | 9472 | | { |
| | 0 | 9473 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9474 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | 0 | 9475 | | { |
| | 0 | 9476 | | goto COMPLETE; |
| | | 9477 | | } |
| | 0 | 9478 | | return; |
| | | 9479 | | } |
| | | 9480 | | } |
| | 0 | 9481 | | catch (Exception ex) |
| | 0 | 9482 | | { |
| | 0 | 9483 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9484 | | self.completedCount = CompleteCount; |
| | 0 | 9485 | | self.completionSource.TrySetException(ex); |
| | 0 | 9486 | | return; |
| | | 9487 | | } |
| | | 9488 | | |
| | 0 | 9489 | | SUCCESS: |
| | 0 | 9490 | | if (!self.TrySetResult()) |
| | 0 | 9491 | | { |
| | 0 | 9492 | | if (self.syncRunning) return; |
| | 0 | 9493 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 9494 | | try |
| | 0 | 9495 | | { |
| | 0 | 9496 | | self.awaiter6 = self.enumerator6.MoveNextAsync().GetAwaiter(); |
| | 0 | 9497 | | } |
| | 0 | 9498 | | catch (Exception ex) |
| | 0 | 9499 | | { |
| | 0 | 9500 | | self.completedCount = CompleteCount; |
| | 0 | 9501 | | self.completionSource.TrySetException(ex); |
| | 0 | 9502 | | return; |
| | | 9503 | | } |
| | | 9504 | | |
| | 0 | 9505 | | self.awaiter6.SourceOnCompleted(Completed6Delegate, self); |
| | 0 | 9506 | | } |
| | 0 | 9507 | | return; |
| | 0 | 9508 | | COMPLETE: |
| | 0 | 9509 | | self.completionSource.TrySetResult(false); |
| | 0 | 9510 | | return; |
| | 0 | 9511 | | } |
| | | 9512 | | |
| | | 9513 | | static void Completed7(object state) |
| | 0 | 9514 | | { |
| | 0 | 9515 | | var self = (_CombineLatest)state; |
| | 0 | 9516 | | self.running7 = false; |
| | | 9517 | | |
| | | 9518 | | try |
| | 0 | 9519 | | { |
| | 0 | 9520 | | if (self.awaiter7.GetResult()) |
| | 0 | 9521 | | { |
| | 0 | 9522 | | self.hasCurrent7 = true; |
| | 0 | 9523 | | self.current7 = self.enumerator7.Current; |
| | 0 | 9524 | | goto SUCCESS; |
| | | 9525 | | } |
| | | 9526 | | else |
| | 0 | 9527 | | { |
| | 0 | 9528 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9529 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | 0 | 9530 | | { |
| | 0 | 9531 | | goto COMPLETE; |
| | | 9532 | | } |
| | 0 | 9533 | | return; |
| | | 9534 | | } |
| | | 9535 | | } |
| | 0 | 9536 | | catch (Exception ex) |
| | 0 | 9537 | | { |
| | 0 | 9538 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9539 | | self.completedCount = CompleteCount; |
| | 0 | 9540 | | self.completionSource.TrySetException(ex); |
| | 0 | 9541 | | return; |
| | | 9542 | | } |
| | | 9543 | | |
| | 0 | 9544 | | SUCCESS: |
| | 0 | 9545 | | if (!self.TrySetResult()) |
| | 0 | 9546 | | { |
| | 0 | 9547 | | if (self.syncRunning) return; |
| | 0 | 9548 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 9549 | | try |
| | 0 | 9550 | | { |
| | 0 | 9551 | | self.awaiter7 = self.enumerator7.MoveNextAsync().GetAwaiter(); |
| | 0 | 9552 | | } |
| | 0 | 9553 | | catch (Exception ex) |
| | 0 | 9554 | | { |
| | 0 | 9555 | | self.completedCount = CompleteCount; |
| | 0 | 9556 | | self.completionSource.TrySetException(ex); |
| | 0 | 9557 | | return; |
| | | 9558 | | } |
| | | 9559 | | |
| | 0 | 9560 | | self.awaiter7.SourceOnCompleted(Completed7Delegate, self); |
| | 0 | 9561 | | } |
| | 0 | 9562 | | return; |
| | 0 | 9563 | | COMPLETE: |
| | 0 | 9564 | | self.completionSource.TrySetResult(false); |
| | 0 | 9565 | | return; |
| | 0 | 9566 | | } |
| | | 9567 | | |
| | | 9568 | | static void Completed8(object state) |
| | 0 | 9569 | | { |
| | 0 | 9570 | | var self = (_CombineLatest)state; |
| | 0 | 9571 | | self.running8 = false; |
| | | 9572 | | |
| | | 9573 | | try |
| | 0 | 9574 | | { |
| | 0 | 9575 | | if (self.awaiter8.GetResult()) |
| | 0 | 9576 | | { |
| | 0 | 9577 | | self.hasCurrent8 = true; |
| | 0 | 9578 | | self.current8 = self.enumerator8.Current; |
| | 0 | 9579 | | goto SUCCESS; |
| | | 9580 | | } |
| | | 9581 | | else |
| | 0 | 9582 | | { |
| | 0 | 9583 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9584 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | 0 | 9585 | | { |
| | 0 | 9586 | | goto COMPLETE; |
| | | 9587 | | } |
| | 0 | 9588 | | return; |
| | | 9589 | | } |
| | | 9590 | | } |
| | 0 | 9591 | | catch (Exception ex) |
| | 0 | 9592 | | { |
| | 0 | 9593 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9594 | | self.completedCount = CompleteCount; |
| | 0 | 9595 | | self.completionSource.TrySetException(ex); |
| | 0 | 9596 | | return; |
| | | 9597 | | } |
| | | 9598 | | |
| | 0 | 9599 | | SUCCESS: |
| | 0 | 9600 | | if (!self.TrySetResult()) |
| | 0 | 9601 | | { |
| | 0 | 9602 | | if (self.syncRunning) return; |
| | 0 | 9603 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 9604 | | try |
| | 0 | 9605 | | { |
| | 0 | 9606 | | self.awaiter8 = self.enumerator8.MoveNextAsync().GetAwaiter(); |
| | 0 | 9607 | | } |
| | 0 | 9608 | | catch (Exception ex) |
| | 0 | 9609 | | { |
| | 0 | 9610 | | self.completedCount = CompleteCount; |
| | 0 | 9611 | | self.completionSource.TrySetException(ex); |
| | 0 | 9612 | | return; |
| | | 9613 | | } |
| | | 9614 | | |
| | 0 | 9615 | | self.awaiter8.SourceOnCompleted(Completed8Delegate, self); |
| | 0 | 9616 | | } |
| | 0 | 9617 | | return; |
| | 0 | 9618 | | COMPLETE: |
| | 0 | 9619 | | self.completionSource.TrySetResult(false); |
| | 0 | 9620 | | return; |
| | 0 | 9621 | | } |
| | | 9622 | | |
| | | 9623 | | static void Completed9(object state) |
| | 0 | 9624 | | { |
| | 0 | 9625 | | var self = (_CombineLatest)state; |
| | 0 | 9626 | | self.running9 = false; |
| | | 9627 | | |
| | | 9628 | | try |
| | 0 | 9629 | | { |
| | 0 | 9630 | | if (self.awaiter9.GetResult()) |
| | 0 | 9631 | | { |
| | 0 | 9632 | | self.hasCurrent9 = true; |
| | 0 | 9633 | | self.current9 = self.enumerator9.Current; |
| | 0 | 9634 | | goto SUCCESS; |
| | | 9635 | | } |
| | | 9636 | | else |
| | 0 | 9637 | | { |
| | 0 | 9638 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9639 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | 0 | 9640 | | { |
| | 0 | 9641 | | goto COMPLETE; |
| | | 9642 | | } |
| | 0 | 9643 | | return; |
| | | 9644 | | } |
| | | 9645 | | } |
| | 0 | 9646 | | catch (Exception ex) |
| | 0 | 9647 | | { |
| | 0 | 9648 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9649 | | self.completedCount = CompleteCount; |
| | 0 | 9650 | | self.completionSource.TrySetException(ex); |
| | 0 | 9651 | | return; |
| | | 9652 | | } |
| | | 9653 | | |
| | 0 | 9654 | | SUCCESS: |
| | 0 | 9655 | | if (!self.TrySetResult()) |
| | 0 | 9656 | | { |
| | 0 | 9657 | | if (self.syncRunning) return; |
| | 0 | 9658 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 9659 | | try |
| | 0 | 9660 | | { |
| | 0 | 9661 | | self.awaiter9 = self.enumerator9.MoveNextAsync().GetAwaiter(); |
| | 0 | 9662 | | } |
| | 0 | 9663 | | catch (Exception ex) |
| | 0 | 9664 | | { |
| | 0 | 9665 | | self.completedCount = CompleteCount; |
| | 0 | 9666 | | self.completionSource.TrySetException(ex); |
| | 0 | 9667 | | return; |
| | | 9668 | | } |
| | | 9669 | | |
| | 0 | 9670 | | self.awaiter9.SourceOnCompleted(Completed9Delegate, self); |
| | 0 | 9671 | | } |
| | 0 | 9672 | | return; |
| | 0 | 9673 | | COMPLETE: |
| | 0 | 9674 | | self.completionSource.TrySetResult(false); |
| | 0 | 9675 | | return; |
| | 0 | 9676 | | } |
| | | 9677 | | |
| | | 9678 | | static void Completed10(object state) |
| | 0 | 9679 | | { |
| | 0 | 9680 | | var self = (_CombineLatest)state; |
| | 0 | 9681 | | self.running10 = false; |
| | | 9682 | | |
| | | 9683 | | try |
| | 0 | 9684 | | { |
| | 0 | 9685 | | if (self.awaiter10.GetResult()) |
| | 0 | 9686 | | { |
| | 0 | 9687 | | self.hasCurrent10 = true; |
| | 0 | 9688 | | self.current10 = self.enumerator10.Current; |
| | 0 | 9689 | | goto SUCCESS; |
| | | 9690 | | } |
| | | 9691 | | else |
| | 0 | 9692 | | { |
| | 0 | 9693 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9694 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | 0 | 9695 | | { |
| | 0 | 9696 | | goto COMPLETE; |
| | | 9697 | | } |
| | 0 | 9698 | | return; |
| | | 9699 | | } |
| | | 9700 | | } |
| | 0 | 9701 | | catch (Exception ex) |
| | 0 | 9702 | | { |
| | 0 | 9703 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9704 | | self.completedCount = CompleteCount; |
| | 0 | 9705 | | self.completionSource.TrySetException(ex); |
| | 0 | 9706 | | return; |
| | | 9707 | | } |
| | | 9708 | | |
| | 0 | 9709 | | SUCCESS: |
| | 0 | 9710 | | if (!self.TrySetResult()) |
| | 0 | 9711 | | { |
| | 0 | 9712 | | if (self.syncRunning) return; |
| | 0 | 9713 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | | 9714 | | try |
| | 0 | 9715 | | { |
| | 0 | 9716 | | self.awaiter10 = self.enumerator10.MoveNextAsync().GetAwaiter(); |
| | 0 | 9717 | | } |
| | 0 | 9718 | | catch (Exception ex) |
| | 0 | 9719 | | { |
| | 0 | 9720 | | self.completedCount = CompleteCount; |
| | 0 | 9721 | | self.completionSource.TrySetException(ex); |
| | 0 | 9722 | | return; |
| | | 9723 | | } |
| | | 9724 | | |
| | 0 | 9725 | | self.awaiter10.SourceOnCompleted(Completed10Delegate, self); |
| | 0 | 9726 | | } |
| | 0 | 9727 | | return; |
| | 0 | 9728 | | COMPLETE: |
| | 0 | 9729 | | self.completionSource.TrySetResult(false); |
| | 0 | 9730 | | return; |
| | 0 | 9731 | | } |
| | | 9732 | | |
| | | 9733 | | static void Completed11(object state) |
| | 0 | 9734 | | { |
| | 0 | 9735 | | var self = (_CombineLatest)state; |
| | 0 | 9736 | | self.running11 = false; |
| | | 9737 | | |
| | | 9738 | | try |
| | 0 | 9739 | | { |
| | 0 | 9740 | | if (self.awaiter11.GetResult()) |
| | 0 | 9741 | | { |
| | 0 | 9742 | | self.hasCurrent11 = true; |
| | 0 | 9743 | | self.current11 = self.enumerator11.Current; |
| | 0 | 9744 | | goto SUCCESS; |
| | | 9745 | | } |
| | | 9746 | | else |
| | 0 | 9747 | | { |
| | 0 | 9748 | | self.running11 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9749 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | 0 | 9750 | | { |
| | 0 | 9751 | | goto COMPLETE; |
| | | 9752 | | } |
| | 0 | 9753 | | return; |
| | | 9754 | | } |
| | | 9755 | | } |
| | 0 | 9756 | | catch (Exception ex) |
| | 0 | 9757 | | { |
| | 0 | 9758 | | self.running11 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9759 | | self.completedCount = CompleteCount; |
| | 0 | 9760 | | self.completionSource.TrySetException(ex); |
| | 0 | 9761 | | return; |
| | | 9762 | | } |
| | | 9763 | | |
| | 0 | 9764 | | SUCCESS: |
| | 0 | 9765 | | if (!self.TrySetResult()) |
| | 0 | 9766 | | { |
| | 0 | 9767 | | if (self.syncRunning) return; |
| | 0 | 9768 | | self.running11 = true; // as complete, no more call MoveNextAsync. |
| | | 9769 | | try |
| | 0 | 9770 | | { |
| | 0 | 9771 | | self.awaiter11 = self.enumerator11.MoveNextAsync().GetAwaiter(); |
| | 0 | 9772 | | } |
| | 0 | 9773 | | catch (Exception ex) |
| | 0 | 9774 | | { |
| | 0 | 9775 | | self.completedCount = CompleteCount; |
| | 0 | 9776 | | self.completionSource.TrySetException(ex); |
| | 0 | 9777 | | return; |
| | | 9778 | | } |
| | | 9779 | | |
| | 0 | 9780 | | self.awaiter11.SourceOnCompleted(Completed11Delegate, self); |
| | 0 | 9781 | | } |
| | 0 | 9782 | | return; |
| | 0 | 9783 | | COMPLETE: |
| | 0 | 9784 | | self.completionSource.TrySetResult(false); |
| | 0 | 9785 | | return; |
| | 0 | 9786 | | } |
| | | 9787 | | |
| | | 9788 | | static void Completed12(object state) |
| | 0 | 9789 | | { |
| | 0 | 9790 | | var self = (_CombineLatest)state; |
| | 0 | 9791 | | self.running12 = false; |
| | | 9792 | | |
| | | 9793 | | try |
| | 0 | 9794 | | { |
| | 0 | 9795 | | if (self.awaiter12.GetResult()) |
| | 0 | 9796 | | { |
| | 0 | 9797 | | self.hasCurrent12 = true; |
| | 0 | 9798 | | self.current12 = self.enumerator12.Current; |
| | 0 | 9799 | | goto SUCCESS; |
| | | 9800 | | } |
| | | 9801 | | else |
| | 0 | 9802 | | { |
| | 0 | 9803 | | self.running12 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9804 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | 0 | 9805 | | { |
| | 0 | 9806 | | goto COMPLETE; |
| | | 9807 | | } |
| | 0 | 9808 | | return; |
| | | 9809 | | } |
| | | 9810 | | } |
| | 0 | 9811 | | catch (Exception ex) |
| | 0 | 9812 | | { |
| | 0 | 9813 | | self.running12 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9814 | | self.completedCount = CompleteCount; |
| | 0 | 9815 | | self.completionSource.TrySetException(ex); |
| | 0 | 9816 | | return; |
| | | 9817 | | } |
| | | 9818 | | |
| | 0 | 9819 | | SUCCESS: |
| | 0 | 9820 | | if (!self.TrySetResult()) |
| | 0 | 9821 | | { |
| | 0 | 9822 | | if (self.syncRunning) return; |
| | 0 | 9823 | | self.running12 = true; // as complete, no more call MoveNextAsync. |
| | | 9824 | | try |
| | 0 | 9825 | | { |
| | 0 | 9826 | | self.awaiter12 = self.enumerator12.MoveNextAsync().GetAwaiter(); |
| | 0 | 9827 | | } |
| | 0 | 9828 | | catch (Exception ex) |
| | 0 | 9829 | | { |
| | 0 | 9830 | | self.completedCount = CompleteCount; |
| | 0 | 9831 | | self.completionSource.TrySetException(ex); |
| | 0 | 9832 | | return; |
| | | 9833 | | } |
| | | 9834 | | |
| | 0 | 9835 | | self.awaiter12.SourceOnCompleted(Completed12Delegate, self); |
| | 0 | 9836 | | } |
| | 0 | 9837 | | return; |
| | 0 | 9838 | | COMPLETE: |
| | 0 | 9839 | | self.completionSource.TrySetResult(false); |
| | 0 | 9840 | | return; |
| | 0 | 9841 | | } |
| | | 9842 | | |
| | | 9843 | | static void Completed13(object state) |
| | 0 | 9844 | | { |
| | 0 | 9845 | | var self = (_CombineLatest)state; |
| | 0 | 9846 | | self.running13 = false; |
| | | 9847 | | |
| | | 9848 | | try |
| | 0 | 9849 | | { |
| | 0 | 9850 | | if (self.awaiter13.GetResult()) |
| | 0 | 9851 | | { |
| | 0 | 9852 | | self.hasCurrent13 = true; |
| | 0 | 9853 | | self.current13 = self.enumerator13.Current; |
| | 0 | 9854 | | goto SUCCESS; |
| | | 9855 | | } |
| | | 9856 | | else |
| | 0 | 9857 | | { |
| | 0 | 9858 | | self.running13 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9859 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | 0 | 9860 | | { |
| | 0 | 9861 | | goto COMPLETE; |
| | | 9862 | | } |
| | 0 | 9863 | | return; |
| | | 9864 | | } |
| | | 9865 | | } |
| | 0 | 9866 | | catch (Exception ex) |
| | 0 | 9867 | | { |
| | 0 | 9868 | | self.running13 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9869 | | self.completedCount = CompleteCount; |
| | 0 | 9870 | | self.completionSource.TrySetException(ex); |
| | 0 | 9871 | | return; |
| | | 9872 | | } |
| | | 9873 | | |
| | 0 | 9874 | | SUCCESS: |
| | 0 | 9875 | | if (!self.TrySetResult()) |
| | 0 | 9876 | | { |
| | 0 | 9877 | | if (self.syncRunning) return; |
| | 0 | 9878 | | self.running13 = true; // as complete, no more call MoveNextAsync. |
| | | 9879 | | try |
| | 0 | 9880 | | { |
| | 0 | 9881 | | self.awaiter13 = self.enumerator13.MoveNextAsync().GetAwaiter(); |
| | 0 | 9882 | | } |
| | 0 | 9883 | | catch (Exception ex) |
| | 0 | 9884 | | { |
| | 0 | 9885 | | self.completedCount = CompleteCount; |
| | 0 | 9886 | | self.completionSource.TrySetException(ex); |
| | 0 | 9887 | | return; |
| | | 9888 | | } |
| | | 9889 | | |
| | 0 | 9890 | | self.awaiter13.SourceOnCompleted(Completed13Delegate, self); |
| | 0 | 9891 | | } |
| | 0 | 9892 | | return; |
| | 0 | 9893 | | COMPLETE: |
| | 0 | 9894 | | self.completionSource.TrySetResult(false); |
| | 0 | 9895 | | return; |
| | 0 | 9896 | | } |
| | | 9897 | | |
| | | 9898 | | static void Completed14(object state) |
| | 0 | 9899 | | { |
| | 0 | 9900 | | var self = (_CombineLatest)state; |
| | 0 | 9901 | | self.running14 = false; |
| | | 9902 | | |
| | | 9903 | | try |
| | 0 | 9904 | | { |
| | 0 | 9905 | | if (self.awaiter14.GetResult()) |
| | 0 | 9906 | | { |
| | 0 | 9907 | | self.hasCurrent14 = true; |
| | 0 | 9908 | | self.current14 = self.enumerator14.Current; |
| | 0 | 9909 | | goto SUCCESS; |
| | | 9910 | | } |
| | | 9911 | | else |
| | 0 | 9912 | | { |
| | 0 | 9913 | | self.running14 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9914 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | 0 | 9915 | | { |
| | 0 | 9916 | | goto COMPLETE; |
| | | 9917 | | } |
| | 0 | 9918 | | return; |
| | | 9919 | | } |
| | | 9920 | | } |
| | 0 | 9921 | | catch (Exception ex) |
| | 0 | 9922 | | { |
| | 0 | 9923 | | self.running14 = true; // as complete, no more call MoveNextAsync. |
| | 0 | 9924 | | self.completedCount = CompleteCount; |
| | 0 | 9925 | | self.completionSource.TrySetException(ex); |
| | 0 | 9926 | | return; |
| | | 9927 | | } |
| | | 9928 | | |
| | 0 | 9929 | | SUCCESS: |
| | 0 | 9930 | | if (!self.TrySetResult()) |
| | 0 | 9931 | | { |
| | 0 | 9932 | | if (self.syncRunning) return; |
| | 0 | 9933 | | self.running14 = true; // as complete, no more call MoveNextAsync. |
| | | 9934 | | try |
| | 0 | 9935 | | { |
| | 0 | 9936 | | self.awaiter14 = self.enumerator14.MoveNextAsync().GetAwaiter(); |
| | 0 | 9937 | | } |
| | 0 | 9938 | | catch (Exception ex) |
| | 0 | 9939 | | { |
| | 0 | 9940 | | self.completedCount = CompleteCount; |
| | 0 | 9941 | | self.completionSource.TrySetException(ex); |
| | 0 | 9942 | | return; |
| | | 9943 | | } |
| | | 9944 | | |
| | 0 | 9945 | | self.awaiter14.SourceOnCompleted(Completed14Delegate, self); |
| | 0 | 9946 | | } |
| | 0 | 9947 | | return; |
| | 0 | 9948 | | COMPLETE: |
| | 0 | 9949 | | self.completionSource.TrySetResult(false); |
| | 0 | 9950 | | return; |
| | 0 | 9951 | | } |
| | | 9952 | | |
| | | 9953 | | bool TrySetResult() |
| | 0 | 9954 | | { |
| | 0 | 9955 | | if (hasCurrent1 && hasCurrent2 && hasCurrent3 && hasCurrent4 && hasCurrent5 && hasCurrent6 && hasCurrent |
| | 0 | 9956 | | { |
| | 0 | 9957 | | result = resultSelector(current1, current2, current3, current4, current5, current6, current7, curren |
| | 0 | 9958 | | completionSource.TrySetResult(true); |
| | 0 | 9959 | | return true; |
| | | 9960 | | } |
| | | 9961 | | else |
| | 0 | 9962 | | { |
| | 0 | 9963 | | return false; |
| | | 9964 | | } |
| | 0 | 9965 | | } |
| | | 9966 | | |
| | | 9967 | | public async UniTask DisposeAsync() |
| | 0 | 9968 | | { |
| | 0 | 9969 | | TaskTracker.RemoveTracking(this); |
| | 0 | 9970 | | if (enumerator1 != null) |
| | 0 | 9971 | | { |
| | 0 | 9972 | | await enumerator1.DisposeAsync(); |
| | 0 | 9973 | | } |
| | 0 | 9974 | | if (enumerator2 != null) |
| | 0 | 9975 | | { |
| | 0 | 9976 | | await enumerator2.DisposeAsync(); |
| | 0 | 9977 | | } |
| | 0 | 9978 | | if (enumerator3 != null) |
| | 0 | 9979 | | { |
| | 0 | 9980 | | await enumerator3.DisposeAsync(); |
| | 0 | 9981 | | } |
| | 0 | 9982 | | if (enumerator4 != null) |
| | 0 | 9983 | | { |
| | 0 | 9984 | | await enumerator4.DisposeAsync(); |
| | 0 | 9985 | | } |
| | 0 | 9986 | | if (enumerator5 != null) |
| | 0 | 9987 | | { |
| | 0 | 9988 | | await enumerator5.DisposeAsync(); |
| | 0 | 9989 | | } |
| | 0 | 9990 | | if (enumerator6 != null) |
| | 0 | 9991 | | { |
| | 0 | 9992 | | await enumerator6.DisposeAsync(); |
| | 0 | 9993 | | } |
| | 0 | 9994 | | if (enumerator7 != null) |
| | 0 | 9995 | | { |
| | 0 | 9996 | | await enumerator7.DisposeAsync(); |
| | 0 | 9997 | | } |
| | 0 | 9998 | | if (enumerator8 != null) |
| | 0 | 9999 | | { |
| | 0 | 10000 | | await enumerator8.DisposeAsync(); |
| | 0 | 10001 | | } |
| | 0 | 10002 | | if (enumerator9 != null) |
| | 0 | 10003 | | { |
| | 0 | 10004 | | await enumerator9.DisposeAsync(); |
| | 0 | 10005 | | } |
| | 0 | 10006 | | if (enumerator10 != null) |
| | 0 | 10007 | | { |
| | 0 | 10008 | | await enumerator10.DisposeAsync(); |
| | 0 | 10009 | | } |
| | 0 | 10010 | | if (enumerator11 != null) |
| | 0 | 10011 | | { |
| | 0 | 10012 | | await enumerator11.DisposeAsync(); |
| | 0 | 10013 | | } |
| | 0 | 10014 | | if (enumerator12 != null) |
| | 0 | 10015 | | { |
| | 0 | 10016 | | await enumerator12.DisposeAsync(); |
| | 0 | 10017 | | } |
| | 0 | 10018 | | if (enumerator13 != null) |
| | 0 | 10019 | | { |
| | 0 | 10020 | | await enumerator13.DisposeAsync(); |
| | 0 | 10021 | | } |
| | 0 | 10022 | | if (enumerator14 != null) |
| | 0 | 10023 | | { |
| | 0 | 10024 | | await enumerator14.DisposeAsync(); |
| | 0 | 10025 | | } |
| | 0 | 10026 | | } |
| | | 10027 | | } |
| | | 10028 | | } |
| | | 10029 | | |
| | | 10030 | | internal class CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult> : IUniTaskAs |
| | | 10031 | | { |
| | | 10032 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 10033 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 10034 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 10035 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 10036 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 10037 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 10038 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 10039 | | readonly IUniTaskAsyncEnumerable<T8> source8; |
| | | 10040 | | readonly IUniTaskAsyncEnumerable<T9> source9; |
| | | 10041 | | readonly IUniTaskAsyncEnumerable<T10> source10; |
| | | 10042 | | readonly IUniTaskAsyncEnumerable<T11> source11; |
| | | 10043 | | readonly IUniTaskAsyncEnumerable<T12> source12; |
| | | 10044 | | readonly IUniTaskAsyncEnumerable<T13> source13; |
| | | 10045 | | readonly IUniTaskAsyncEnumerable<T14> source14; |
| | | 10046 | | readonly IUniTaskAsyncEnumerable<T15> source15; |
| | | 10047 | | |
| | | 10048 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult> resultSelector; |
| | | 10049 | | |
| | | 10050 | | public CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyncEnum |
| | | 10051 | | { |
| | | 10052 | | this.source1 = source1; |
| | | 10053 | | this.source2 = source2; |
| | | 10054 | | this.source3 = source3; |
| | | 10055 | | this.source4 = source4; |
| | | 10056 | | this.source5 = source5; |
| | | 10057 | | this.source6 = source6; |
| | | 10058 | | this.source7 = source7; |
| | | 10059 | | this.source8 = source8; |
| | | 10060 | | this.source9 = source9; |
| | | 10061 | | this.source10 = source10; |
| | | 10062 | | this.source11 = source11; |
| | | 10063 | | this.source12 = source12; |
| | | 10064 | | this.source13 = source13; |
| | | 10065 | | this.source14 = source14; |
| | | 10066 | | this.source15 = source15; |
| | | 10067 | | |
| | | 10068 | | this.resultSelector = resultSelector; |
| | | 10069 | | } |
| | | 10070 | | |
| | | 10071 | | public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default) |
| | | 10072 | | { |
| | | 10073 | | return new _CombineLatest(source1, source2, source3, source4, source5, source6, source7, source8, source9, s |
| | | 10074 | | } |
| | | 10075 | | |
| | | 10076 | | class _CombineLatest : MoveNextSource, IUniTaskAsyncEnumerator<TResult> |
| | | 10077 | | { |
| | | 10078 | | static readonly Action<object> Completed1Delegate = Completed1; |
| | | 10079 | | static readonly Action<object> Completed2Delegate = Completed2; |
| | | 10080 | | static readonly Action<object> Completed3Delegate = Completed3; |
| | | 10081 | | static readonly Action<object> Completed4Delegate = Completed4; |
| | | 10082 | | static readonly Action<object> Completed5Delegate = Completed5; |
| | | 10083 | | static readonly Action<object> Completed6Delegate = Completed6; |
| | | 10084 | | static readonly Action<object> Completed7Delegate = Completed7; |
| | | 10085 | | static readonly Action<object> Completed8Delegate = Completed8; |
| | | 10086 | | static readonly Action<object> Completed9Delegate = Completed9; |
| | | 10087 | | static readonly Action<object> Completed10Delegate = Completed10; |
| | | 10088 | | static readonly Action<object> Completed11Delegate = Completed11; |
| | | 10089 | | static readonly Action<object> Completed12Delegate = Completed12; |
| | | 10090 | | static readonly Action<object> Completed13Delegate = Completed13; |
| | | 10091 | | static readonly Action<object> Completed14Delegate = Completed14; |
| | | 10092 | | static readonly Action<object> Completed15Delegate = Completed15; |
| | | 10093 | | const int CompleteCount = 15; |
| | | 10094 | | |
| | | 10095 | | readonly IUniTaskAsyncEnumerable<T1> source1; |
| | | 10096 | | readonly IUniTaskAsyncEnumerable<T2> source2; |
| | | 10097 | | readonly IUniTaskAsyncEnumerable<T3> source3; |
| | | 10098 | | readonly IUniTaskAsyncEnumerable<T4> source4; |
| | | 10099 | | readonly IUniTaskAsyncEnumerable<T5> source5; |
| | | 10100 | | readonly IUniTaskAsyncEnumerable<T6> source6; |
| | | 10101 | | readonly IUniTaskAsyncEnumerable<T7> source7; |
| | | 10102 | | readonly IUniTaskAsyncEnumerable<T8> source8; |
| | | 10103 | | readonly IUniTaskAsyncEnumerable<T9> source9; |
| | | 10104 | | readonly IUniTaskAsyncEnumerable<T10> source10; |
| | | 10105 | | readonly IUniTaskAsyncEnumerable<T11> source11; |
| | | 10106 | | readonly IUniTaskAsyncEnumerable<T12> source12; |
| | | 10107 | | readonly IUniTaskAsyncEnumerable<T13> source13; |
| | | 10108 | | readonly IUniTaskAsyncEnumerable<T14> source14; |
| | | 10109 | | readonly IUniTaskAsyncEnumerable<T15> source15; |
| | | 10110 | | |
| | | 10111 | | readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult> resultSelector; |
| | | 10112 | | CancellationToken cancellationToken; |
| | | 10113 | | |
| | | 10114 | | IUniTaskAsyncEnumerator<T1> enumerator1; |
| | | 10115 | | UniTask<bool>.Awaiter awaiter1; |
| | | 10116 | | bool hasCurrent1; |
| | | 10117 | | bool running1; |
| | | 10118 | | T1 current1; |
| | | 10119 | | |
| | | 10120 | | IUniTaskAsyncEnumerator<T2> enumerator2; |
| | | 10121 | | UniTask<bool>.Awaiter awaiter2; |
| | | 10122 | | bool hasCurrent2; |
| | | 10123 | | bool running2; |
| | | 10124 | | T2 current2; |
| | | 10125 | | |
| | | 10126 | | IUniTaskAsyncEnumerator<T3> enumerator3; |
| | | 10127 | | UniTask<bool>.Awaiter awaiter3; |
| | | 10128 | | bool hasCurrent3; |
| | | 10129 | | bool running3; |
| | | 10130 | | T3 current3; |
| | | 10131 | | |
| | | 10132 | | IUniTaskAsyncEnumerator<T4> enumerator4; |
| | | 10133 | | UniTask<bool>.Awaiter awaiter4; |
| | | 10134 | | bool hasCurrent4; |
| | | 10135 | | bool running4; |
| | | 10136 | | T4 current4; |
| | | 10137 | | |
| | | 10138 | | IUniTaskAsyncEnumerator<T5> enumerator5; |
| | | 10139 | | UniTask<bool>.Awaiter awaiter5; |
| | | 10140 | | bool hasCurrent5; |
| | | 10141 | | bool running5; |
| | | 10142 | | T5 current5; |
| | | 10143 | | |
| | | 10144 | | IUniTaskAsyncEnumerator<T6> enumerator6; |
| | | 10145 | | UniTask<bool>.Awaiter awaiter6; |
| | | 10146 | | bool hasCurrent6; |
| | | 10147 | | bool running6; |
| | | 10148 | | T6 current6; |
| | | 10149 | | |
| | | 10150 | | IUniTaskAsyncEnumerator<T7> enumerator7; |
| | | 10151 | | UniTask<bool>.Awaiter awaiter7; |
| | | 10152 | | bool hasCurrent7; |
| | | 10153 | | bool running7; |
| | | 10154 | | T7 current7; |
| | | 10155 | | |
| | | 10156 | | IUniTaskAsyncEnumerator<T8> enumerator8; |
| | | 10157 | | UniTask<bool>.Awaiter awaiter8; |
| | | 10158 | | bool hasCurrent8; |
| | | 10159 | | bool running8; |
| | | 10160 | | T8 current8; |
| | | 10161 | | |
| | | 10162 | | IUniTaskAsyncEnumerator<T9> enumerator9; |
| | | 10163 | | UniTask<bool>.Awaiter awaiter9; |
| | | 10164 | | bool hasCurrent9; |
| | | 10165 | | bool running9; |
| | | 10166 | | T9 current9; |
| | | 10167 | | |
| | | 10168 | | IUniTaskAsyncEnumerator<T10> enumerator10; |
| | | 10169 | | UniTask<bool>.Awaiter awaiter10; |
| | | 10170 | | bool hasCurrent10; |
| | | 10171 | | bool running10; |
| | | 10172 | | T10 current10; |
| | | 10173 | | |
| | | 10174 | | IUniTaskAsyncEnumerator<T11> enumerator11; |
| | | 10175 | | UniTask<bool>.Awaiter awaiter11; |
| | | 10176 | | bool hasCurrent11; |
| | | 10177 | | bool running11; |
| | | 10178 | | T11 current11; |
| | | 10179 | | |
| | | 10180 | | IUniTaskAsyncEnumerator<T12> enumerator12; |
| | | 10181 | | UniTask<bool>.Awaiter awaiter12; |
| | | 10182 | | bool hasCurrent12; |
| | | 10183 | | bool running12; |
| | | 10184 | | T12 current12; |
| | | 10185 | | |
| | | 10186 | | IUniTaskAsyncEnumerator<T13> enumerator13; |
| | | 10187 | | UniTask<bool>.Awaiter awaiter13; |
| | | 10188 | | bool hasCurrent13; |
| | | 10189 | | bool running13; |
| | | 10190 | | T13 current13; |
| | | 10191 | | |
| | | 10192 | | IUniTaskAsyncEnumerator<T14> enumerator14; |
| | | 10193 | | UniTask<bool>.Awaiter awaiter14; |
| | | 10194 | | bool hasCurrent14; |
| | | 10195 | | bool running14; |
| | | 10196 | | T14 current14; |
| | | 10197 | | |
| | | 10198 | | IUniTaskAsyncEnumerator<T15> enumerator15; |
| | | 10199 | | UniTask<bool>.Awaiter awaiter15; |
| | | 10200 | | bool hasCurrent15; |
| | | 10201 | | bool running15; |
| | | 10202 | | T15 current15; |
| | | 10203 | | |
| | | 10204 | | int completedCount; |
| | | 10205 | | bool syncRunning; |
| | | 10206 | | TResult result; |
| | | 10207 | | |
| | | 10208 | | public _CombineLatest(IUniTaskAsyncEnumerable<T1> source1, IUniTaskAsyncEnumerable<T2> source2, IUniTaskAsyn |
| | | 10209 | | { |
| | | 10210 | | this.source1 = source1; |
| | | 10211 | | this.source2 = source2; |
| | | 10212 | | this.source3 = source3; |
| | | 10213 | | this.source4 = source4; |
| | | 10214 | | this.source5 = source5; |
| | | 10215 | | this.source6 = source6; |
| | | 10216 | | this.source7 = source7; |
| | | 10217 | | this.source8 = source8; |
| | | 10218 | | this.source9 = source9; |
| | | 10219 | | this.source10 = source10; |
| | | 10220 | | this.source11 = source11; |
| | | 10221 | | this.source12 = source12; |
| | | 10222 | | this.source13 = source13; |
| | | 10223 | | this.source14 = source14; |
| | | 10224 | | this.source15 = source15; |
| | | 10225 | | |
| | | 10226 | | this.resultSelector = resultSelector; |
| | | 10227 | | this.cancellationToken = cancellationToken; |
| | | 10228 | | TaskTracker.TrackActiveTask(this, 3); |
| | | 10229 | | } |
| | | 10230 | | |
| | | 10231 | | public TResult Current => result; |
| | | 10232 | | |
| | | 10233 | | public UniTask<bool> MoveNextAsync() |
| | | 10234 | | { |
| | | 10235 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 10236 | | if (completedCount == CompleteCount) return CompletedTasks.False; |
| | | 10237 | | |
| | | 10238 | | if (enumerator1 == null) |
| | | 10239 | | { |
| | | 10240 | | enumerator1 = source1.GetAsyncEnumerator(cancellationToken); |
| | | 10241 | | enumerator2 = source2.GetAsyncEnumerator(cancellationToken); |
| | | 10242 | | enumerator3 = source3.GetAsyncEnumerator(cancellationToken); |
| | | 10243 | | enumerator4 = source4.GetAsyncEnumerator(cancellationToken); |
| | | 10244 | | enumerator5 = source5.GetAsyncEnumerator(cancellationToken); |
| | | 10245 | | enumerator6 = source6.GetAsyncEnumerator(cancellationToken); |
| | | 10246 | | enumerator7 = source7.GetAsyncEnumerator(cancellationToken); |
| | | 10247 | | enumerator8 = source8.GetAsyncEnumerator(cancellationToken); |
| | | 10248 | | enumerator9 = source9.GetAsyncEnumerator(cancellationToken); |
| | | 10249 | | enumerator10 = source10.GetAsyncEnumerator(cancellationToken); |
| | | 10250 | | enumerator11 = source11.GetAsyncEnumerator(cancellationToken); |
| | | 10251 | | enumerator12 = source12.GetAsyncEnumerator(cancellationToken); |
| | | 10252 | | enumerator13 = source13.GetAsyncEnumerator(cancellationToken); |
| | | 10253 | | enumerator14 = source14.GetAsyncEnumerator(cancellationToken); |
| | | 10254 | | enumerator15 = source15.GetAsyncEnumerator(cancellationToken); |
| | | 10255 | | } |
| | | 10256 | | |
| | | 10257 | | completionSource.Reset(); |
| | | 10258 | | |
| | | 10259 | | AGAIN: |
| | | 10260 | | syncRunning = true; |
| | | 10261 | | if (!running1) |
| | | 10262 | | { |
| | | 10263 | | running1 = true; |
| | | 10264 | | awaiter1 = enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 10265 | | if (awaiter1.IsCompleted) |
| | | 10266 | | { |
| | | 10267 | | Completed1(this); |
| | | 10268 | | } |
| | | 10269 | | else |
| | | 10270 | | { |
| | | 10271 | | awaiter1.SourceOnCompleted(Completed1Delegate, this); |
| | | 10272 | | } |
| | | 10273 | | } |
| | | 10274 | | if (!running2) |
| | | 10275 | | { |
| | | 10276 | | running2 = true; |
| | | 10277 | | awaiter2 = enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 10278 | | if (awaiter2.IsCompleted) |
| | | 10279 | | { |
| | | 10280 | | Completed2(this); |
| | | 10281 | | } |
| | | 10282 | | else |
| | | 10283 | | { |
| | | 10284 | | awaiter2.SourceOnCompleted(Completed2Delegate, this); |
| | | 10285 | | } |
| | | 10286 | | } |
| | | 10287 | | if (!running3) |
| | | 10288 | | { |
| | | 10289 | | running3 = true; |
| | | 10290 | | awaiter3 = enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 10291 | | if (awaiter3.IsCompleted) |
| | | 10292 | | { |
| | | 10293 | | Completed3(this); |
| | | 10294 | | } |
| | | 10295 | | else |
| | | 10296 | | { |
| | | 10297 | | awaiter3.SourceOnCompleted(Completed3Delegate, this); |
| | | 10298 | | } |
| | | 10299 | | } |
| | | 10300 | | if (!running4) |
| | | 10301 | | { |
| | | 10302 | | running4 = true; |
| | | 10303 | | awaiter4 = enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 10304 | | if (awaiter4.IsCompleted) |
| | | 10305 | | { |
| | | 10306 | | Completed4(this); |
| | | 10307 | | } |
| | | 10308 | | else |
| | | 10309 | | { |
| | | 10310 | | awaiter4.SourceOnCompleted(Completed4Delegate, this); |
| | | 10311 | | } |
| | | 10312 | | } |
| | | 10313 | | if (!running5) |
| | | 10314 | | { |
| | | 10315 | | running5 = true; |
| | | 10316 | | awaiter5 = enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 10317 | | if (awaiter5.IsCompleted) |
| | | 10318 | | { |
| | | 10319 | | Completed5(this); |
| | | 10320 | | } |
| | | 10321 | | else |
| | | 10322 | | { |
| | | 10323 | | awaiter5.SourceOnCompleted(Completed5Delegate, this); |
| | | 10324 | | } |
| | | 10325 | | } |
| | | 10326 | | if (!running6) |
| | | 10327 | | { |
| | | 10328 | | running6 = true; |
| | | 10329 | | awaiter6 = enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 10330 | | if (awaiter6.IsCompleted) |
| | | 10331 | | { |
| | | 10332 | | Completed6(this); |
| | | 10333 | | } |
| | | 10334 | | else |
| | | 10335 | | { |
| | | 10336 | | awaiter6.SourceOnCompleted(Completed6Delegate, this); |
| | | 10337 | | } |
| | | 10338 | | } |
| | | 10339 | | if (!running7) |
| | | 10340 | | { |
| | | 10341 | | running7 = true; |
| | | 10342 | | awaiter7 = enumerator7.MoveNextAsync().GetAwaiter(); |
| | | 10343 | | if (awaiter7.IsCompleted) |
| | | 10344 | | { |
| | | 10345 | | Completed7(this); |
| | | 10346 | | } |
| | | 10347 | | else |
| | | 10348 | | { |
| | | 10349 | | awaiter7.SourceOnCompleted(Completed7Delegate, this); |
| | | 10350 | | } |
| | | 10351 | | } |
| | | 10352 | | if (!running8) |
| | | 10353 | | { |
| | | 10354 | | running8 = true; |
| | | 10355 | | awaiter8 = enumerator8.MoveNextAsync().GetAwaiter(); |
| | | 10356 | | if (awaiter8.IsCompleted) |
| | | 10357 | | { |
| | | 10358 | | Completed8(this); |
| | | 10359 | | } |
| | | 10360 | | else |
| | | 10361 | | { |
| | | 10362 | | awaiter8.SourceOnCompleted(Completed8Delegate, this); |
| | | 10363 | | } |
| | | 10364 | | } |
| | | 10365 | | if (!running9) |
| | | 10366 | | { |
| | | 10367 | | running9 = true; |
| | | 10368 | | awaiter9 = enumerator9.MoveNextAsync().GetAwaiter(); |
| | | 10369 | | if (awaiter9.IsCompleted) |
| | | 10370 | | { |
| | | 10371 | | Completed9(this); |
| | | 10372 | | } |
| | | 10373 | | else |
| | | 10374 | | { |
| | | 10375 | | awaiter9.SourceOnCompleted(Completed9Delegate, this); |
| | | 10376 | | } |
| | | 10377 | | } |
| | | 10378 | | if (!running10) |
| | | 10379 | | { |
| | | 10380 | | running10 = true; |
| | | 10381 | | awaiter10 = enumerator10.MoveNextAsync().GetAwaiter(); |
| | | 10382 | | if (awaiter10.IsCompleted) |
| | | 10383 | | { |
| | | 10384 | | Completed10(this); |
| | | 10385 | | } |
| | | 10386 | | else |
| | | 10387 | | { |
| | | 10388 | | awaiter10.SourceOnCompleted(Completed10Delegate, this); |
| | | 10389 | | } |
| | | 10390 | | } |
| | | 10391 | | if (!running11) |
| | | 10392 | | { |
| | | 10393 | | running11 = true; |
| | | 10394 | | awaiter11 = enumerator11.MoveNextAsync().GetAwaiter(); |
| | | 10395 | | if (awaiter11.IsCompleted) |
| | | 10396 | | { |
| | | 10397 | | Completed11(this); |
| | | 10398 | | } |
| | | 10399 | | else |
| | | 10400 | | { |
| | | 10401 | | awaiter11.SourceOnCompleted(Completed11Delegate, this); |
| | | 10402 | | } |
| | | 10403 | | } |
| | | 10404 | | if (!running12) |
| | | 10405 | | { |
| | | 10406 | | running12 = true; |
| | | 10407 | | awaiter12 = enumerator12.MoveNextAsync().GetAwaiter(); |
| | | 10408 | | if (awaiter12.IsCompleted) |
| | | 10409 | | { |
| | | 10410 | | Completed12(this); |
| | | 10411 | | } |
| | | 10412 | | else |
| | | 10413 | | { |
| | | 10414 | | awaiter12.SourceOnCompleted(Completed12Delegate, this); |
| | | 10415 | | } |
| | | 10416 | | } |
| | | 10417 | | if (!running13) |
| | | 10418 | | { |
| | | 10419 | | running13 = true; |
| | | 10420 | | awaiter13 = enumerator13.MoveNextAsync().GetAwaiter(); |
| | | 10421 | | if (awaiter13.IsCompleted) |
| | | 10422 | | { |
| | | 10423 | | Completed13(this); |
| | | 10424 | | } |
| | | 10425 | | else |
| | | 10426 | | { |
| | | 10427 | | awaiter13.SourceOnCompleted(Completed13Delegate, this); |
| | | 10428 | | } |
| | | 10429 | | } |
| | | 10430 | | if (!running14) |
| | | 10431 | | { |
| | | 10432 | | running14 = true; |
| | | 10433 | | awaiter14 = enumerator14.MoveNextAsync().GetAwaiter(); |
| | | 10434 | | if (awaiter14.IsCompleted) |
| | | 10435 | | { |
| | | 10436 | | Completed14(this); |
| | | 10437 | | } |
| | | 10438 | | else |
| | | 10439 | | { |
| | | 10440 | | awaiter14.SourceOnCompleted(Completed14Delegate, this); |
| | | 10441 | | } |
| | | 10442 | | } |
| | | 10443 | | if (!running15) |
| | | 10444 | | { |
| | | 10445 | | running15 = true; |
| | | 10446 | | awaiter15 = enumerator15.MoveNextAsync().GetAwaiter(); |
| | | 10447 | | if (awaiter15.IsCompleted) |
| | | 10448 | | { |
| | | 10449 | | Completed15(this); |
| | | 10450 | | } |
| | | 10451 | | else |
| | | 10452 | | { |
| | | 10453 | | awaiter15.SourceOnCompleted(Completed15Delegate, this); |
| | | 10454 | | } |
| | | 10455 | | } |
| | | 10456 | | |
| | | 10457 | | if (!running1 || !running2 || !running3 || !running4 || !running5 || !running6 || !running7 || !running8 |
| | | 10458 | | { |
| | | 10459 | | goto AGAIN; |
| | | 10460 | | } |
| | | 10461 | | syncRunning = false; |
| | | 10462 | | |
| | | 10463 | | return new UniTask<bool>(this, completionSource.Version); |
| | | 10464 | | } |
| | | 10465 | | |
| | | 10466 | | static void Completed1(object state) |
| | | 10467 | | { |
| | | 10468 | | var self = (_CombineLatest)state; |
| | | 10469 | | self.running1 = false; |
| | | 10470 | | |
| | | 10471 | | try |
| | | 10472 | | { |
| | | 10473 | | if (self.awaiter1.GetResult()) |
| | | 10474 | | { |
| | | 10475 | | self.hasCurrent1 = true; |
| | | 10476 | | self.current1 = self.enumerator1.Current; |
| | | 10477 | | goto SUCCESS; |
| | | 10478 | | } |
| | | 10479 | | else |
| | | 10480 | | { |
| | | 10481 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 10482 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 10483 | | { |
| | | 10484 | | goto COMPLETE; |
| | | 10485 | | } |
| | | 10486 | | return; |
| | | 10487 | | } |
| | | 10488 | | } |
| | | 10489 | | catch (Exception ex) |
| | | 10490 | | { |
| | | 10491 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 10492 | | self.completedCount = CompleteCount; |
| | | 10493 | | self.completionSource.TrySetException(ex); |
| | | 10494 | | return; |
| | | 10495 | | } |
| | | 10496 | | |
| | | 10497 | | SUCCESS: |
| | | 10498 | | if (!self.TrySetResult()) |
| | | 10499 | | { |
| | | 10500 | | if (self.syncRunning) return; |
| | | 10501 | | self.running1 = true; // as complete, no more call MoveNextAsync. |
| | | 10502 | | try |
| | | 10503 | | { |
| | | 10504 | | self.awaiter1 = self.enumerator1.MoveNextAsync().GetAwaiter(); |
| | | 10505 | | } |
| | | 10506 | | catch (Exception ex) |
| | | 10507 | | { |
| | | 10508 | | self.completedCount = CompleteCount; |
| | | 10509 | | self.completionSource.TrySetException(ex); |
| | | 10510 | | return; |
| | | 10511 | | } |
| | | 10512 | | |
| | | 10513 | | self.awaiter1.SourceOnCompleted(Completed1Delegate, self); |
| | | 10514 | | } |
| | | 10515 | | return; |
| | | 10516 | | COMPLETE: |
| | | 10517 | | self.completionSource.TrySetResult(false); |
| | | 10518 | | return; |
| | | 10519 | | } |
| | | 10520 | | |
| | | 10521 | | static void Completed2(object state) |
| | | 10522 | | { |
| | | 10523 | | var self = (_CombineLatest)state; |
| | | 10524 | | self.running2 = false; |
| | | 10525 | | |
| | | 10526 | | try |
| | | 10527 | | { |
| | | 10528 | | if (self.awaiter2.GetResult()) |
| | | 10529 | | { |
| | | 10530 | | self.hasCurrent2 = true; |
| | | 10531 | | self.current2 = self.enumerator2.Current; |
| | | 10532 | | goto SUCCESS; |
| | | 10533 | | } |
| | | 10534 | | else |
| | | 10535 | | { |
| | | 10536 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 10537 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 10538 | | { |
| | | 10539 | | goto COMPLETE; |
| | | 10540 | | } |
| | | 10541 | | return; |
| | | 10542 | | } |
| | | 10543 | | } |
| | | 10544 | | catch (Exception ex) |
| | | 10545 | | { |
| | | 10546 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 10547 | | self.completedCount = CompleteCount; |
| | | 10548 | | self.completionSource.TrySetException(ex); |
| | | 10549 | | return; |
| | | 10550 | | } |
| | | 10551 | | |
| | | 10552 | | SUCCESS: |
| | | 10553 | | if (!self.TrySetResult()) |
| | | 10554 | | { |
| | | 10555 | | if (self.syncRunning) return; |
| | | 10556 | | self.running2 = true; // as complete, no more call MoveNextAsync. |
| | | 10557 | | try |
| | | 10558 | | { |
| | | 10559 | | self.awaiter2 = self.enumerator2.MoveNextAsync().GetAwaiter(); |
| | | 10560 | | } |
| | | 10561 | | catch (Exception ex) |
| | | 10562 | | { |
| | | 10563 | | self.completedCount = CompleteCount; |
| | | 10564 | | self.completionSource.TrySetException(ex); |
| | | 10565 | | return; |
| | | 10566 | | } |
| | | 10567 | | |
| | | 10568 | | self.awaiter2.SourceOnCompleted(Completed2Delegate, self); |
| | | 10569 | | } |
| | | 10570 | | return; |
| | | 10571 | | COMPLETE: |
| | | 10572 | | self.completionSource.TrySetResult(false); |
| | | 10573 | | return; |
| | | 10574 | | } |
| | | 10575 | | |
| | | 10576 | | static void Completed3(object state) |
| | | 10577 | | { |
| | | 10578 | | var self = (_CombineLatest)state; |
| | | 10579 | | self.running3 = false; |
| | | 10580 | | |
| | | 10581 | | try |
| | | 10582 | | { |
| | | 10583 | | if (self.awaiter3.GetResult()) |
| | | 10584 | | { |
| | | 10585 | | self.hasCurrent3 = true; |
| | | 10586 | | self.current3 = self.enumerator3.Current; |
| | | 10587 | | goto SUCCESS; |
| | | 10588 | | } |
| | | 10589 | | else |
| | | 10590 | | { |
| | | 10591 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 10592 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 10593 | | { |
| | | 10594 | | goto COMPLETE; |
| | | 10595 | | } |
| | | 10596 | | return; |
| | | 10597 | | } |
| | | 10598 | | } |
| | | 10599 | | catch (Exception ex) |
| | | 10600 | | { |
| | | 10601 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 10602 | | self.completedCount = CompleteCount; |
| | | 10603 | | self.completionSource.TrySetException(ex); |
| | | 10604 | | return; |
| | | 10605 | | } |
| | | 10606 | | |
| | | 10607 | | SUCCESS: |
| | | 10608 | | if (!self.TrySetResult()) |
| | | 10609 | | { |
| | | 10610 | | if (self.syncRunning) return; |
| | | 10611 | | self.running3 = true; // as complete, no more call MoveNextAsync. |
| | | 10612 | | try |
| | | 10613 | | { |
| | | 10614 | | self.awaiter3 = self.enumerator3.MoveNextAsync().GetAwaiter(); |
| | | 10615 | | } |
| | | 10616 | | catch (Exception ex) |
| | | 10617 | | { |
| | | 10618 | | self.completedCount = CompleteCount; |
| | | 10619 | | self.completionSource.TrySetException(ex); |
| | | 10620 | | return; |
| | | 10621 | | } |
| | | 10622 | | |
| | | 10623 | | self.awaiter3.SourceOnCompleted(Completed3Delegate, self); |
| | | 10624 | | } |
| | | 10625 | | return; |
| | | 10626 | | COMPLETE: |
| | | 10627 | | self.completionSource.TrySetResult(false); |
| | | 10628 | | return; |
| | | 10629 | | } |
| | | 10630 | | |
| | | 10631 | | static void Completed4(object state) |
| | | 10632 | | { |
| | | 10633 | | var self = (_CombineLatest)state; |
| | | 10634 | | self.running4 = false; |
| | | 10635 | | |
| | | 10636 | | try |
| | | 10637 | | { |
| | | 10638 | | if (self.awaiter4.GetResult()) |
| | | 10639 | | { |
| | | 10640 | | self.hasCurrent4 = true; |
| | | 10641 | | self.current4 = self.enumerator4.Current; |
| | | 10642 | | goto SUCCESS; |
| | | 10643 | | } |
| | | 10644 | | else |
| | | 10645 | | { |
| | | 10646 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 10647 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 10648 | | { |
| | | 10649 | | goto COMPLETE; |
| | | 10650 | | } |
| | | 10651 | | return; |
| | | 10652 | | } |
| | | 10653 | | } |
| | | 10654 | | catch (Exception ex) |
| | | 10655 | | { |
| | | 10656 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 10657 | | self.completedCount = CompleteCount; |
| | | 10658 | | self.completionSource.TrySetException(ex); |
| | | 10659 | | return; |
| | | 10660 | | } |
| | | 10661 | | |
| | | 10662 | | SUCCESS: |
| | | 10663 | | if (!self.TrySetResult()) |
| | | 10664 | | { |
| | | 10665 | | if (self.syncRunning) return; |
| | | 10666 | | self.running4 = true; // as complete, no more call MoveNextAsync. |
| | | 10667 | | try |
| | | 10668 | | { |
| | | 10669 | | self.awaiter4 = self.enumerator4.MoveNextAsync().GetAwaiter(); |
| | | 10670 | | } |
| | | 10671 | | catch (Exception ex) |
| | | 10672 | | { |
| | | 10673 | | self.completedCount = CompleteCount; |
| | | 10674 | | self.completionSource.TrySetException(ex); |
| | | 10675 | | return; |
| | | 10676 | | } |
| | | 10677 | | |
| | | 10678 | | self.awaiter4.SourceOnCompleted(Completed4Delegate, self); |
| | | 10679 | | } |
| | | 10680 | | return; |
| | | 10681 | | COMPLETE: |
| | | 10682 | | self.completionSource.TrySetResult(false); |
| | | 10683 | | return; |
| | | 10684 | | } |
| | | 10685 | | |
| | | 10686 | | static void Completed5(object state) |
| | | 10687 | | { |
| | | 10688 | | var self = (_CombineLatest)state; |
| | | 10689 | | self.running5 = false; |
| | | 10690 | | |
| | | 10691 | | try |
| | | 10692 | | { |
| | | 10693 | | if (self.awaiter5.GetResult()) |
| | | 10694 | | { |
| | | 10695 | | self.hasCurrent5 = true; |
| | | 10696 | | self.current5 = self.enumerator5.Current; |
| | | 10697 | | goto SUCCESS; |
| | | 10698 | | } |
| | | 10699 | | else |
| | | 10700 | | { |
| | | 10701 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 10702 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 10703 | | { |
| | | 10704 | | goto COMPLETE; |
| | | 10705 | | } |
| | | 10706 | | return; |
| | | 10707 | | } |
| | | 10708 | | } |
| | | 10709 | | catch (Exception ex) |
| | | 10710 | | { |
| | | 10711 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 10712 | | self.completedCount = CompleteCount; |
| | | 10713 | | self.completionSource.TrySetException(ex); |
| | | 10714 | | return; |
| | | 10715 | | } |
| | | 10716 | | |
| | | 10717 | | SUCCESS: |
| | | 10718 | | if (!self.TrySetResult()) |
| | | 10719 | | { |
| | | 10720 | | if (self.syncRunning) return; |
| | | 10721 | | self.running5 = true; // as complete, no more call MoveNextAsync. |
| | | 10722 | | try |
| | | 10723 | | { |
| | | 10724 | | self.awaiter5 = self.enumerator5.MoveNextAsync().GetAwaiter(); |
| | | 10725 | | } |
| | | 10726 | | catch (Exception ex) |
| | | 10727 | | { |
| | | 10728 | | self.completedCount = CompleteCount; |
| | | 10729 | | self.completionSource.TrySetException(ex); |
| | | 10730 | | return; |
| | | 10731 | | } |
| | | 10732 | | |
| | | 10733 | | self.awaiter5.SourceOnCompleted(Completed5Delegate, self); |
| | | 10734 | | } |
| | | 10735 | | return; |
| | | 10736 | | COMPLETE: |
| | | 10737 | | self.completionSource.TrySetResult(false); |
| | | 10738 | | return; |
| | | 10739 | | } |
| | | 10740 | | |
| | | 10741 | | static void Completed6(object state) |
| | | 10742 | | { |
| | | 10743 | | var self = (_CombineLatest)state; |
| | | 10744 | | self.running6 = false; |
| | | 10745 | | |
| | | 10746 | | try |
| | | 10747 | | { |
| | | 10748 | | if (self.awaiter6.GetResult()) |
| | | 10749 | | { |
| | | 10750 | | self.hasCurrent6 = true; |
| | | 10751 | | self.current6 = self.enumerator6.Current; |
| | | 10752 | | goto SUCCESS; |
| | | 10753 | | } |
| | | 10754 | | else |
| | | 10755 | | { |
| | | 10756 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 10757 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 10758 | | { |
| | | 10759 | | goto COMPLETE; |
| | | 10760 | | } |
| | | 10761 | | return; |
| | | 10762 | | } |
| | | 10763 | | } |
| | | 10764 | | catch (Exception ex) |
| | | 10765 | | { |
| | | 10766 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 10767 | | self.completedCount = CompleteCount; |
| | | 10768 | | self.completionSource.TrySetException(ex); |
| | | 10769 | | return; |
| | | 10770 | | } |
| | | 10771 | | |
| | | 10772 | | SUCCESS: |
| | | 10773 | | if (!self.TrySetResult()) |
| | | 10774 | | { |
| | | 10775 | | if (self.syncRunning) return; |
| | | 10776 | | self.running6 = true; // as complete, no more call MoveNextAsync. |
| | | 10777 | | try |
| | | 10778 | | { |
| | | 10779 | | self.awaiter6 = self.enumerator6.MoveNextAsync().GetAwaiter(); |
| | | 10780 | | } |
| | | 10781 | | catch (Exception ex) |
| | | 10782 | | { |
| | | 10783 | | self.completedCount = CompleteCount; |
| | | 10784 | | self.completionSource.TrySetException(ex); |
| | | 10785 | | return; |
| | | 10786 | | } |
| | | 10787 | | |
| | | 10788 | | self.awaiter6.SourceOnCompleted(Completed6Delegate, self); |
| | | 10789 | | } |
| | | 10790 | | return; |
| | | 10791 | | COMPLETE: |
| | | 10792 | | self.completionSource.TrySetResult(false); |
| | | 10793 | | return; |
| | | 10794 | | } |
| | | 10795 | | |
| | | 10796 | | static void Completed7(object state) |
| | | 10797 | | { |
| | | 10798 | | var self = (_CombineLatest)state; |
| | | 10799 | | self.running7 = false; |
| | | 10800 | | |
| | | 10801 | | try |
| | | 10802 | | { |
| | | 10803 | | if (self.awaiter7.GetResult()) |
| | | 10804 | | { |
| | | 10805 | | self.hasCurrent7 = true; |
| | | 10806 | | self.current7 = self.enumerator7.Current; |
| | | 10807 | | goto SUCCESS; |
| | | 10808 | | } |
| | | 10809 | | else |
| | | 10810 | | { |
| | | 10811 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 10812 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 10813 | | { |
| | | 10814 | | goto COMPLETE; |
| | | 10815 | | } |
| | | 10816 | | return; |
| | | 10817 | | } |
| | | 10818 | | } |
| | | 10819 | | catch (Exception ex) |
| | | 10820 | | { |
| | | 10821 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 10822 | | self.completedCount = CompleteCount; |
| | | 10823 | | self.completionSource.TrySetException(ex); |
| | | 10824 | | return; |
| | | 10825 | | } |
| | | 10826 | | |
| | | 10827 | | SUCCESS: |
| | | 10828 | | if (!self.TrySetResult()) |
| | | 10829 | | { |
| | | 10830 | | if (self.syncRunning) return; |
| | | 10831 | | self.running7 = true; // as complete, no more call MoveNextAsync. |
| | | 10832 | | try |
| | | 10833 | | { |
| | | 10834 | | self.awaiter7 = self.enumerator7.MoveNextAsync().GetAwaiter(); |
| | | 10835 | | } |
| | | 10836 | | catch (Exception ex) |
| | | 10837 | | { |
| | | 10838 | | self.completedCount = CompleteCount; |
| | | 10839 | | self.completionSource.TrySetException(ex); |
| | | 10840 | | return; |
| | | 10841 | | } |
| | | 10842 | | |
| | | 10843 | | self.awaiter7.SourceOnCompleted(Completed7Delegate, self); |
| | | 10844 | | } |
| | | 10845 | | return; |
| | | 10846 | | COMPLETE: |
| | | 10847 | | self.completionSource.TrySetResult(false); |
| | | 10848 | | return; |
| | | 10849 | | } |
| | | 10850 | | |
| | | 10851 | | static void Completed8(object state) |
| | | 10852 | | { |
| | | 10853 | | var self = (_CombineLatest)state; |
| | | 10854 | | self.running8 = false; |
| | | 10855 | | |
| | | 10856 | | try |
| | | 10857 | | { |
| | | 10858 | | if (self.awaiter8.GetResult()) |
| | | 10859 | | { |
| | | 10860 | | self.hasCurrent8 = true; |
| | | 10861 | | self.current8 = self.enumerator8.Current; |
| | | 10862 | | goto SUCCESS; |
| | | 10863 | | } |
| | | 10864 | | else |
| | | 10865 | | { |
| | | 10866 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 10867 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 10868 | | { |
| | | 10869 | | goto COMPLETE; |
| | | 10870 | | } |
| | | 10871 | | return; |
| | | 10872 | | } |
| | | 10873 | | } |
| | | 10874 | | catch (Exception ex) |
| | | 10875 | | { |
| | | 10876 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 10877 | | self.completedCount = CompleteCount; |
| | | 10878 | | self.completionSource.TrySetException(ex); |
| | | 10879 | | return; |
| | | 10880 | | } |
| | | 10881 | | |
| | | 10882 | | SUCCESS: |
| | | 10883 | | if (!self.TrySetResult()) |
| | | 10884 | | { |
| | | 10885 | | if (self.syncRunning) return; |
| | | 10886 | | self.running8 = true; // as complete, no more call MoveNextAsync. |
| | | 10887 | | try |
| | | 10888 | | { |
| | | 10889 | | self.awaiter8 = self.enumerator8.MoveNextAsync().GetAwaiter(); |
| | | 10890 | | } |
| | | 10891 | | catch (Exception ex) |
| | | 10892 | | { |
| | | 10893 | | self.completedCount = CompleteCount; |
| | | 10894 | | self.completionSource.TrySetException(ex); |
| | | 10895 | | return; |
| | | 10896 | | } |
| | | 10897 | | |
| | | 10898 | | self.awaiter8.SourceOnCompleted(Completed8Delegate, self); |
| | | 10899 | | } |
| | | 10900 | | return; |
| | | 10901 | | COMPLETE: |
| | | 10902 | | self.completionSource.TrySetResult(false); |
| | | 10903 | | return; |
| | | 10904 | | } |
| | | 10905 | | |
| | | 10906 | | static void Completed9(object state) |
| | | 10907 | | { |
| | | 10908 | | var self = (_CombineLatest)state; |
| | | 10909 | | self.running9 = false; |
| | | 10910 | | |
| | | 10911 | | try |
| | | 10912 | | { |
| | | 10913 | | if (self.awaiter9.GetResult()) |
| | | 10914 | | { |
| | | 10915 | | self.hasCurrent9 = true; |
| | | 10916 | | self.current9 = self.enumerator9.Current; |
| | | 10917 | | goto SUCCESS; |
| | | 10918 | | } |
| | | 10919 | | else |
| | | 10920 | | { |
| | | 10921 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 10922 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 10923 | | { |
| | | 10924 | | goto COMPLETE; |
| | | 10925 | | } |
| | | 10926 | | return; |
| | | 10927 | | } |
| | | 10928 | | } |
| | | 10929 | | catch (Exception ex) |
| | | 10930 | | { |
| | | 10931 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 10932 | | self.completedCount = CompleteCount; |
| | | 10933 | | self.completionSource.TrySetException(ex); |
| | | 10934 | | return; |
| | | 10935 | | } |
| | | 10936 | | |
| | | 10937 | | SUCCESS: |
| | | 10938 | | if (!self.TrySetResult()) |
| | | 10939 | | { |
| | | 10940 | | if (self.syncRunning) return; |
| | | 10941 | | self.running9 = true; // as complete, no more call MoveNextAsync. |
| | | 10942 | | try |
| | | 10943 | | { |
| | | 10944 | | self.awaiter9 = self.enumerator9.MoveNextAsync().GetAwaiter(); |
| | | 10945 | | } |
| | | 10946 | | catch (Exception ex) |
| | | 10947 | | { |
| | | 10948 | | self.completedCount = CompleteCount; |
| | | 10949 | | self.completionSource.TrySetException(ex); |
| | | 10950 | | return; |
| | | 10951 | | } |
| | | 10952 | | |
| | | 10953 | | self.awaiter9.SourceOnCompleted(Completed9Delegate, self); |
| | | 10954 | | } |
| | | 10955 | | return; |
| | | 10956 | | COMPLETE: |
| | | 10957 | | self.completionSource.TrySetResult(false); |
| | | 10958 | | return; |
| | | 10959 | | } |
| | | 10960 | | |
| | | 10961 | | static void Completed10(object state) |
| | | 10962 | | { |
| | | 10963 | | var self = (_CombineLatest)state; |
| | | 10964 | | self.running10 = false; |
| | | 10965 | | |
| | | 10966 | | try |
| | | 10967 | | { |
| | | 10968 | | if (self.awaiter10.GetResult()) |
| | | 10969 | | { |
| | | 10970 | | self.hasCurrent10 = true; |
| | | 10971 | | self.current10 = self.enumerator10.Current; |
| | | 10972 | | goto SUCCESS; |
| | | 10973 | | } |
| | | 10974 | | else |
| | | 10975 | | { |
| | | 10976 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | | 10977 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 10978 | | { |
| | | 10979 | | goto COMPLETE; |
| | | 10980 | | } |
| | | 10981 | | return; |
| | | 10982 | | } |
| | | 10983 | | } |
| | | 10984 | | catch (Exception ex) |
| | | 10985 | | { |
| | | 10986 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | | 10987 | | self.completedCount = CompleteCount; |
| | | 10988 | | self.completionSource.TrySetException(ex); |
| | | 10989 | | return; |
| | | 10990 | | } |
| | | 10991 | | |
| | | 10992 | | SUCCESS: |
| | | 10993 | | if (!self.TrySetResult()) |
| | | 10994 | | { |
| | | 10995 | | if (self.syncRunning) return; |
| | | 10996 | | self.running10 = true; // as complete, no more call MoveNextAsync. |
| | | 10997 | | try |
| | | 10998 | | { |
| | | 10999 | | self.awaiter10 = self.enumerator10.MoveNextAsync().GetAwaiter(); |
| | | 11000 | | } |
| | | 11001 | | catch (Exception ex) |
| | | 11002 | | { |
| | | 11003 | | self.completedCount = CompleteCount; |
| | | 11004 | | self.completionSource.TrySetException(ex); |
| | | 11005 | | return; |
| | | 11006 | | } |
| | | 11007 | | |
| | | 11008 | | self.awaiter10.SourceOnCompleted(Completed10Delegate, self); |
| | | 11009 | | } |
| | | 11010 | | return; |
| | | 11011 | | COMPLETE: |
| | | 11012 | | self.completionSource.TrySetResult(false); |
| | | 11013 | | return; |
| | | 11014 | | } |
| | | 11015 | | |
| | | 11016 | | static void Completed11(object state) |
| | | 11017 | | { |
| | | 11018 | | var self = (_CombineLatest)state; |
| | | 11019 | | self.running11 = false; |
| | | 11020 | | |
| | | 11021 | | try |
| | | 11022 | | { |
| | | 11023 | | if (self.awaiter11.GetResult()) |
| | | 11024 | | { |
| | | 11025 | | self.hasCurrent11 = true; |
| | | 11026 | | self.current11 = self.enumerator11.Current; |
| | | 11027 | | goto SUCCESS; |
| | | 11028 | | } |
| | | 11029 | | else |
| | | 11030 | | { |
| | | 11031 | | self.running11 = true; // as complete, no more call MoveNextAsync. |
| | | 11032 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 11033 | | { |
| | | 11034 | | goto COMPLETE; |
| | | 11035 | | } |
| | | 11036 | | return; |
| | | 11037 | | } |
| | | 11038 | | } |
| | | 11039 | | catch (Exception ex) |
| | | 11040 | | { |
| | | 11041 | | self.running11 = true; // as complete, no more call MoveNextAsync. |
| | | 11042 | | self.completedCount = CompleteCount; |
| | | 11043 | | self.completionSource.TrySetException(ex); |
| | | 11044 | | return; |
| | | 11045 | | } |
| | | 11046 | | |
| | | 11047 | | SUCCESS: |
| | | 11048 | | if (!self.TrySetResult()) |
| | | 11049 | | { |
| | | 11050 | | if (self.syncRunning) return; |
| | | 11051 | | self.running11 = true; // as complete, no more call MoveNextAsync. |
| | | 11052 | | try |
| | | 11053 | | { |
| | | 11054 | | self.awaiter11 = self.enumerator11.MoveNextAsync().GetAwaiter(); |
| | | 11055 | | } |
| | | 11056 | | catch (Exception ex) |
| | | 11057 | | { |
| | | 11058 | | self.completedCount = CompleteCount; |
| | | 11059 | | self.completionSource.TrySetException(ex); |
| | | 11060 | | return; |
| | | 11061 | | } |
| | | 11062 | | |
| | | 11063 | | self.awaiter11.SourceOnCompleted(Completed11Delegate, self); |
| | | 11064 | | } |
| | | 11065 | | return; |
| | | 11066 | | COMPLETE: |
| | | 11067 | | self.completionSource.TrySetResult(false); |
| | | 11068 | | return; |
| | | 11069 | | } |
| | | 11070 | | |
| | | 11071 | | static void Completed12(object state) |
| | | 11072 | | { |
| | | 11073 | | var self = (_CombineLatest)state; |
| | | 11074 | | self.running12 = false; |
| | | 11075 | | |
| | | 11076 | | try |
| | | 11077 | | { |
| | | 11078 | | if (self.awaiter12.GetResult()) |
| | | 11079 | | { |
| | | 11080 | | self.hasCurrent12 = true; |
| | | 11081 | | self.current12 = self.enumerator12.Current; |
| | | 11082 | | goto SUCCESS; |
| | | 11083 | | } |
| | | 11084 | | else |
| | | 11085 | | { |
| | | 11086 | | self.running12 = true; // as complete, no more call MoveNextAsync. |
| | | 11087 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 11088 | | { |
| | | 11089 | | goto COMPLETE; |
| | | 11090 | | } |
| | | 11091 | | return; |
| | | 11092 | | } |
| | | 11093 | | } |
| | | 11094 | | catch (Exception ex) |
| | | 11095 | | { |
| | | 11096 | | self.running12 = true; // as complete, no more call MoveNextAsync. |
| | | 11097 | | self.completedCount = CompleteCount; |
| | | 11098 | | self.completionSource.TrySetException(ex); |
| | | 11099 | | return; |
| | | 11100 | | } |
| | | 11101 | | |
| | | 11102 | | SUCCESS: |
| | | 11103 | | if (!self.TrySetResult()) |
| | | 11104 | | { |
| | | 11105 | | if (self.syncRunning) return; |
| | | 11106 | | self.running12 = true; // as complete, no more call MoveNextAsync. |
| | | 11107 | | try |
| | | 11108 | | { |
| | | 11109 | | self.awaiter12 = self.enumerator12.MoveNextAsync().GetAwaiter(); |
| | | 11110 | | } |
| | | 11111 | | catch (Exception ex) |
| | | 11112 | | { |
| | | 11113 | | self.completedCount = CompleteCount; |
| | | 11114 | | self.completionSource.TrySetException(ex); |
| | | 11115 | | return; |
| | | 11116 | | } |
| | | 11117 | | |
| | | 11118 | | self.awaiter12.SourceOnCompleted(Completed12Delegate, self); |
| | | 11119 | | } |
| | | 11120 | | return; |
| | | 11121 | | COMPLETE: |
| | | 11122 | | self.completionSource.TrySetResult(false); |
| | | 11123 | | return; |
| | | 11124 | | } |
| | | 11125 | | |
| | | 11126 | | static void Completed13(object state) |
| | | 11127 | | { |
| | | 11128 | | var self = (_CombineLatest)state; |
| | | 11129 | | self.running13 = false; |
| | | 11130 | | |
| | | 11131 | | try |
| | | 11132 | | { |
| | | 11133 | | if (self.awaiter13.GetResult()) |
| | | 11134 | | { |
| | | 11135 | | self.hasCurrent13 = true; |
| | | 11136 | | self.current13 = self.enumerator13.Current; |
| | | 11137 | | goto SUCCESS; |
| | | 11138 | | } |
| | | 11139 | | else |
| | | 11140 | | { |
| | | 11141 | | self.running13 = true; // as complete, no more call MoveNextAsync. |
| | | 11142 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 11143 | | { |
| | | 11144 | | goto COMPLETE; |
| | | 11145 | | } |
| | | 11146 | | return; |
| | | 11147 | | } |
| | | 11148 | | } |
| | | 11149 | | catch (Exception ex) |
| | | 11150 | | { |
| | | 11151 | | self.running13 = true; // as complete, no more call MoveNextAsync. |
| | | 11152 | | self.completedCount = CompleteCount; |
| | | 11153 | | self.completionSource.TrySetException(ex); |
| | | 11154 | | return; |
| | | 11155 | | } |
| | | 11156 | | |
| | | 11157 | | SUCCESS: |
| | | 11158 | | if (!self.TrySetResult()) |
| | | 11159 | | { |
| | | 11160 | | if (self.syncRunning) return; |
| | | 11161 | | self.running13 = true; // as complete, no more call MoveNextAsync. |
| | | 11162 | | try |
| | | 11163 | | { |
| | | 11164 | | self.awaiter13 = self.enumerator13.MoveNextAsync().GetAwaiter(); |
| | | 11165 | | } |
| | | 11166 | | catch (Exception ex) |
| | | 11167 | | { |
| | | 11168 | | self.completedCount = CompleteCount; |
| | | 11169 | | self.completionSource.TrySetException(ex); |
| | | 11170 | | return; |
| | | 11171 | | } |
| | | 11172 | | |
| | | 11173 | | self.awaiter13.SourceOnCompleted(Completed13Delegate, self); |
| | | 11174 | | } |
| | | 11175 | | return; |
| | | 11176 | | COMPLETE: |
| | | 11177 | | self.completionSource.TrySetResult(false); |
| | | 11178 | | return; |
| | | 11179 | | } |
| | | 11180 | | |
| | | 11181 | | static void Completed14(object state) |
| | | 11182 | | { |
| | | 11183 | | var self = (_CombineLatest)state; |
| | | 11184 | | self.running14 = false; |
| | | 11185 | | |
| | | 11186 | | try |
| | | 11187 | | { |
| | | 11188 | | if (self.awaiter14.GetResult()) |
| | | 11189 | | { |
| | | 11190 | | self.hasCurrent14 = true; |
| | | 11191 | | self.current14 = self.enumerator14.Current; |
| | | 11192 | | goto SUCCESS; |
| | | 11193 | | } |
| | | 11194 | | else |
| | | 11195 | | { |
| | | 11196 | | self.running14 = true; // as complete, no more call MoveNextAsync. |
| | | 11197 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 11198 | | { |
| | | 11199 | | goto COMPLETE; |
| | | 11200 | | } |
| | | 11201 | | return; |
| | | 11202 | | } |
| | | 11203 | | } |
| | | 11204 | | catch (Exception ex) |
| | | 11205 | | { |
| | | 11206 | | self.running14 = true; // as complete, no more call MoveNextAsync. |
| | | 11207 | | self.completedCount = CompleteCount; |
| | | 11208 | | self.completionSource.TrySetException(ex); |
| | | 11209 | | return; |
| | | 11210 | | } |
| | | 11211 | | |
| | | 11212 | | SUCCESS: |
| | | 11213 | | if (!self.TrySetResult()) |
| | | 11214 | | { |
| | | 11215 | | if (self.syncRunning) return; |
| | | 11216 | | self.running14 = true; // as complete, no more call MoveNextAsync. |
| | | 11217 | | try |
| | | 11218 | | { |
| | | 11219 | | self.awaiter14 = self.enumerator14.MoveNextAsync().GetAwaiter(); |
| | | 11220 | | } |
| | | 11221 | | catch (Exception ex) |
| | | 11222 | | { |
| | | 11223 | | self.completedCount = CompleteCount; |
| | | 11224 | | self.completionSource.TrySetException(ex); |
| | | 11225 | | return; |
| | | 11226 | | } |
| | | 11227 | | |
| | | 11228 | | self.awaiter14.SourceOnCompleted(Completed14Delegate, self); |
| | | 11229 | | } |
| | | 11230 | | return; |
| | | 11231 | | COMPLETE: |
| | | 11232 | | self.completionSource.TrySetResult(false); |
| | | 11233 | | return; |
| | | 11234 | | } |
| | | 11235 | | |
| | | 11236 | | static void Completed15(object state) |
| | | 11237 | | { |
| | | 11238 | | var self = (_CombineLatest)state; |
| | | 11239 | | self.running15 = false; |
| | | 11240 | | |
| | | 11241 | | try |
| | | 11242 | | { |
| | | 11243 | | if (self.awaiter15.GetResult()) |
| | | 11244 | | { |
| | | 11245 | | self.hasCurrent15 = true; |
| | | 11246 | | self.current15 = self.enumerator15.Current; |
| | | 11247 | | goto SUCCESS; |
| | | 11248 | | } |
| | | 11249 | | else |
| | | 11250 | | { |
| | | 11251 | | self.running15 = true; // as complete, no more call MoveNextAsync. |
| | | 11252 | | if (Interlocked.Increment(ref self.completedCount) == CompleteCount) |
| | | 11253 | | { |
| | | 11254 | | goto COMPLETE; |
| | | 11255 | | } |
| | | 11256 | | return; |
| | | 11257 | | } |
| | | 11258 | | } |
| | | 11259 | | catch (Exception ex) |
| | | 11260 | | { |
| | | 11261 | | self.running15 = true; // as complete, no more call MoveNextAsync. |
| | | 11262 | | self.completedCount = CompleteCount; |
| | | 11263 | | self.completionSource.TrySetException(ex); |
| | | 11264 | | return; |
| | | 11265 | | } |
| | | 11266 | | |
| | | 11267 | | SUCCESS: |
| | | 11268 | | if (!self.TrySetResult()) |
| | | 11269 | | { |
| | | 11270 | | if (self.syncRunning) return; |
| | | 11271 | | self.running15 = true; // as complete, no more call MoveNextAsync. |
| | | 11272 | | try |
| | | 11273 | | { |
| | | 11274 | | self.awaiter15 = self.enumerator15.MoveNextAsync().GetAwaiter(); |
| | | 11275 | | } |
| | | 11276 | | catch (Exception ex) |
| | | 11277 | | { |
| | | 11278 | | self.completedCount = CompleteCount; |
| | | 11279 | | self.completionSource.TrySetException(ex); |
| | | 11280 | | return; |
| | | 11281 | | } |
| | | 11282 | | |
| | | 11283 | | self.awaiter15.SourceOnCompleted(Completed15Delegate, self); |
| | | 11284 | | } |
| | | 11285 | | return; |
| | | 11286 | | COMPLETE: |
| | | 11287 | | self.completionSource.TrySetResult(false); |
| | | 11288 | | return; |
| | | 11289 | | } |
| | | 11290 | | |
| | | 11291 | | bool TrySetResult() |
| | | 11292 | | { |
| | | 11293 | | if (hasCurrent1 && hasCurrent2 && hasCurrent3 && hasCurrent4 && hasCurrent5 && hasCurrent6 && hasCurrent |
| | | 11294 | | { |
| | | 11295 | | result = resultSelector(current1, current2, current3, current4, current5, current6, current7, curren |
| | | 11296 | | completionSource.TrySetResult(true); |
| | | 11297 | | return true; |
| | | 11298 | | } |
| | | 11299 | | else |
| | | 11300 | | { |
| | | 11301 | | return false; |
| | | 11302 | | } |
| | | 11303 | | } |
| | | 11304 | | |
| | | 11305 | | public async UniTask DisposeAsync() |
| | | 11306 | | { |
| | | 11307 | | TaskTracker.RemoveTracking(this); |
| | | 11308 | | if (enumerator1 != null) |
| | | 11309 | | { |
| | | 11310 | | await enumerator1.DisposeAsync(); |
| | | 11311 | | } |
| | | 11312 | | if (enumerator2 != null) |
| | | 11313 | | { |
| | | 11314 | | await enumerator2.DisposeAsync(); |
| | | 11315 | | } |
| | | 11316 | | if (enumerator3 != null) |
| | | 11317 | | { |
| | | 11318 | | await enumerator3.DisposeAsync(); |
| | | 11319 | | } |
| | | 11320 | | if (enumerator4 != null) |
| | | 11321 | | { |
| | | 11322 | | await enumerator4.DisposeAsync(); |
| | | 11323 | | } |
| | | 11324 | | if (enumerator5 != null) |
| | | 11325 | | { |
| | | 11326 | | await enumerator5.DisposeAsync(); |
| | | 11327 | | } |
| | | 11328 | | if (enumerator6 != null) |
| | | 11329 | | { |
| | | 11330 | | await enumerator6.DisposeAsync(); |
| | | 11331 | | } |
| | | 11332 | | if (enumerator7 != null) |
| | | 11333 | | { |
| | | 11334 | | await enumerator7.DisposeAsync(); |
| | | 11335 | | } |
| | | 11336 | | if (enumerator8 != null) |
| | | 11337 | | { |
| | | 11338 | | await enumerator8.DisposeAsync(); |
| | | 11339 | | } |
| | | 11340 | | if (enumerator9 != null) |
| | | 11341 | | { |
| | | 11342 | | await enumerator9.DisposeAsync(); |
| | | 11343 | | } |
| | | 11344 | | if (enumerator10 != null) |
| | | 11345 | | { |
| | | 11346 | | await enumerator10.DisposeAsync(); |
| | | 11347 | | } |
| | | 11348 | | if (enumerator11 != null) |
| | | 11349 | | { |
| | | 11350 | | await enumerator11.DisposeAsync(); |
| | | 11351 | | } |
| | | 11352 | | if (enumerator12 != null) |
| | | 11353 | | { |
| | | 11354 | | await enumerator12.DisposeAsync(); |
| | | 11355 | | } |
| | | 11356 | | if (enumerator13 != null) |
| | | 11357 | | { |
| | | 11358 | | await enumerator13.DisposeAsync(); |
| | | 11359 | | } |
| | | 11360 | | if (enumerator14 != null) |
| | | 11361 | | { |
| | | 11362 | | await enumerator14.DisposeAsync(); |
| | | 11363 | | } |
| | | 11364 | | if (enumerator15 != null) |
| | | 11365 | | { |
| | | 11366 | | await enumerator15.DisposeAsync(); |
| | | 11367 | | } |
| | | 11368 | | } |
| | | 11369 | | } |
| | | 11370 | | } |
| | | 11371 | | |
| | | 11372 | | } |